<!DOCTYPE html><html class="theme-next gemini use-motion" lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1"><meta name="theme-color" content="#222"><script src="//cdn.bootcss.com/pace/1.0.2/pace.min.js"></script><link href="//cdn.bootcss.com/pace/1.0.2/themes/pink/pace-theme-flash.css" rel="stylesheet"><style>.pace .pace-progress{background:#1e92fb;height:3px}.pace .pace-progress-inner{box-shadow:0 0 10px #1e92fb,0 0 5px #1e92fb}.pace .pace-activity{border-top-color:#1e92fb;border-left-color:#1e92fb}</style><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><link href="/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css"><link href="/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css"><link href="/css/main.css?v=5.1.4" rel="stylesheet" type="text/css"><link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png?v=5.1.4"><link rel="icon" type="image/png" sizes="32x32" href="/images/favicon.ico?v=5.1.4"><link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png?v=5.1.4"><link rel="mask-icon" href="/images/logo.svg?v=5.1.4" color="#222"><meta name="keywords" content="ReactNative,"><link rel="alternate" href="/atom.xml" title="It is written" type="application/atom+xml"><meta name="description" content="抖音APP原型图地址： http:&#x2F;&#x2F;cloud.axureshop.com&#x2F;S4UIH5&#x2F;#id&#x3D;a9fqgo&amp;p&#x3D;app%E7%A7%BB%E5%8A%A8%E7%AB%AF&amp;sc&#x3D;2&amp;dp&#x3D;0&amp;fn&#x3D;0 码云：https:&#x2F;&#x2F;gitee.com&#x2F;King-XiYu&#x2F;rn-douyin-app"><meta property="og:type" content="article"><meta property="og:title" content="React Native -- 仿抖音APP开发"><meta property="og:url" content="http://king-xiyu.gitee.io/article/3d977fbc.html"><meta property="og:site_name" content="It is written"><meta property="og:description" content="抖音APP原型图地址： http:&#x2F;&#x2F;cloud.axureshop.com&#x2F;S4UIH5&#x2F;#id&#x3D;a9fqgo&amp;p&#x3D;app%E7%A7%BB%E5%8A%A8%E7%AB%AF&amp;sc&#x3D;2&amp;dp&#x3D;0&amp;fn&#x3D;0 码云：https:&#x2F;&#x2F;gitee.com&#x2F;King-XiYu&#x2F;rn-douyin-app"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gevuzqrqh4j320612w7wh.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gevvzko7b5j30xp0nzgqj.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gevw8ejj3cj310y0o5jwu.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gevwhcr77yj30yk0ox0x6.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gevwn50c74j31250nbdjj.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gevwzxc2uvj30vt0qqjvk.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gewwnmtfhnj30bm0n54f8.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gewuxr1z7fj30tr0m8q5y.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1geww1u5fhej30ro0m9q5t.jpg"><meta property="og:image" content="https://img.kancloud.cn/a7/df/a7df5e1ff65d2b3e39471d8f8975d33e_352x146.png"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gex13aqqgvj30bl0oqq4g.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gezb3ow8yej310c0qw436.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gezbit0lscj30uu0t7qfm.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gezbqx3zrvj30p20ob0vv.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gezbrcc5q1j30a90cu74k.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gex1awy6ujj30hy02q3yx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gex1b5z7ppj30k203emy3.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gex1dkn38oj30um0n6q6k.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gex1szauohj30lb0rktb1.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gex1uac1zoj31pi17shdt.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gex1v8kiu0j30fi09cmxr.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1jcomc9ij311v0p7q7t.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1jd7k211j319c0gyn66.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kx1p5vcj31720zewy3.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kxqfoctj31ne0zgx6p.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1ko9rwl6j31p0192b2a.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kpc7g3ij31200fs4cu.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kslij3zj31o21467wi.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kthnvy7j30ji0bok0g.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1ku5e83dj31pe1ayb2a.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kusi9eij30ya1bwb29.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kvec0o9j312813aqop.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kw7uhb6j30xe0piapn.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kzej0phj31r00c21kx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kzv0geij311c0vckjl.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2nh2xsrij30qq11se81.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ninkty6j31js0uqe81.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2o4gsw8yj31i80us1kx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ocye9u5j319i13ib29.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2odnbzw2j30uo0a6jx7.jpg"><meta property="og:image" content="https://img.kancloud.cn/63/f3/63f3031567b83c6040eb8337a254d4ba_672x1202.png"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2pyd2ng6j324o0kenpd.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2pz6x1oxj30mu1a2tsl.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2pzo7rumj31480uunj2.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q066a65j30tu0vuh8d.jpg"><meta property="og:image" content="https://img.kancloud.cn/0e/22/0e22ef53f76e0e2f2cecea4619f170a2_1192x1718.png"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q15jmxlj31bs1287wh.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q1uqqshj315q0y04ge.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q2ki4m8j30xs0d4jzu.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q2s04z8j317s0w61kx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q3sq572j311o19m4qp.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q48zdekj30x21ackgg.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2rgd7r16j31xi11qkjl.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ruza1r4j31mi12cb29.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2rxmway3j31l80lck9c.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2rywv67yj31k20xmu0j.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2rzlmol0j319q0g0n7p.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2se1ct0qj31hy0mk1iy.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2segttp2j31i213m4qp.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2seq7csej31e012ynpd.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sez7qwaj31bs14qkjl.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sfh3ibsj31ok0v8b29.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sfolcn8j31040nkwuu.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sg0ccc5j30wi0nwneg.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sh0xfk6j30do078dgt.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sihr2mwj315210ie81.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sjik27dj31so11kqv5.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sks30gkj31ws114npe.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2skhxf36j312y0bsthh.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sk9uw66j31o40kme81.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2tx0p90pj30jo0aetbe.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2twicp2kj314w16i1kx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2tw9o612j31680wyqtm.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2tw2753yj31rs128npd.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2tvske1kj31fw15cnpd.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u26iixoj31e61ccx6p.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u2ntk6ij30hu0yo14o.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u8x5z2mj31by19ib29.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u8nzupgj31jm14sb29.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u8awx48j31pi1bsx6p.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u82yo0lj31ne0ymb29.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u7tbgkoj30wa0fi7bg.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u7kn5ooj31a81aihdt.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u7cfxc9j31n4104hdt.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u73kes5j30b2078wgx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u6v1i3fj31m0182qv5.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u6dz30bj314q1941kx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uc8eg95j30y40oe7wh.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ucqtevcj31ci15ghdt.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uk63iv9j31gc0h8trn.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ujx4b21j30ew09wadj.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ujq1kfmj31ek180npd.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ujfde05j30sk0dadle.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uj6awpkj315u162x2b.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ui7vkukj30sa0huwmb.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uhxhpyyj31go0fqh0k.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uhmmob6j316q0jcaqx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uhe4yp0j30te0j4ws6.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uh42otwj318g0qse3a.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ugpc5l0j318q0qs7wf.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w51xt34j321s15cnpe.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w4tomlkj321o14ke82.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w4m8faej31g015ce82.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w4bt4vpj325k1064qq.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w43ufmhj310g0c2dnn.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w3v88jwj30ts0wunf4.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w3nsd3qj30qm0eqahg.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w3e7udwj30vs0i4gvq.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w36nspzj318g0ge4en.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w2p3xlbj31ce0f8ne5.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w2wt7s9j30ki0pkqcu.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w2gto6yj31200rynfv.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w259fb3j31160esgw8.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w1x0u5pj30y20l8nd1.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w1pxponj313m0g2ncp.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w1ipnhaj314i0mwavy.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w138kbcj31a613y4qp.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w0dqsofj31eo1224qp.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w05fjd0j31eu13stzu.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vzuypdyj30us0fsqd1.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vznm9evj30ow0cq0yj.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vzfqbccj31fs0ww7o6.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vz8ol4zj31780t44qp.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vyyj2m1j31aa15c1kx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vybvzbfj30ts09wafx.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vyjoxq8j314m0o8kdq.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vy2nizvj30rs0kadp5.jpg"><meta property="og:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vxvdnasj31i40z0e81.jpg"><meta property="article:published_time" content="2020-05-17T14:44:48.000Z"><meta property="article:modified_time" content="2020-09-01T00:45:13.856Z"><meta property="article:author" content="King-XiYu"><meta property="article:tag" content="ReactNative"><meta name="twitter:card" content="summary"><meta name="twitter:image" content="http://ww1.sinaimg.cn/large/007WurYGgy1gevuzqrqh4j320612w7wh.jpg"><script type="text/javascript" id="hexo.configurations">var NexT=window.NexT||{},CONFIG={root:"/",scheme:"Gemini",version:"5.1.4",sidebar:{position:"left",display:"post",offset:12,b2t:!0,scrollpercent:!0,onmobile:!1},fancybox:!0,tabs:!0,motion:{enable:!0,async:!1,transition:{post_block:"fadeIn",post_header:"slideDownIn",post_body:"slideDownIn",coll_header:"slideLeftIn",sidebar:"slideUpIn"}},duoshuo:{userId:"0",author:"博主"},algolia:{applicationID:"",apiKey:"",indexName:"",hits:{per_page:10},labels:{input_placeholder:"Search for Posts",hits_empty:"We didn't find any results for the search: ${query}",hits_stats:"${hits} results found in ${time} ms"}}}</script><link rel="canonical" href="http://king-xiyu.gitee.io/article/3d977fbc.html"><title>React Native -- 仿抖音APP开发 | It is written</title><meta name="generator" content="Hexo 4.2.0"></head><body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans"><div class="container sidebar-position-left page-post-detail"><div class="headband"></div><header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader"><div class="header-inner"><div class="site-brand-wrapper"><div class="site-meta"><div class="custom-logo-site-title"><a href="/" class="brand" rel="start"><span class="logo-line-before"><i></i></span> <span class="site-title">It is written</span><span class="logo-line-after"><i></i></span></a></div><p class="site-subtitle"></p></div><div class="site-nav-toggle"> <button><span class="btn-bar"></span><span class="btn-bar"></span><span class="btn-bar"></span></button></div></div><nav class="site-nav"><ul id="menu" class="menu"><li class="menu-item menu-item-home"><a href="/" rel="section"><i class="menu-item-icon fa fa-fw fa-home"></i><br> 首页</a></li><li class="menu-item menu-item-tags"><a href="/tags/" rel="section"><i class="menu-item-icon fa fa-fw fa-tags"></i><br> 标签</a></li><li class="menu-item menu-item-categories"><a href="/categories/" rel="section"><i class="menu-item-icon fa fa-fw fa-th"></i><br> 分类</a></li><li class="menu-item menu-item-archives"><a href="/archives/" rel="section"><i class="menu-item-icon fa fa-fw fa-archive"></i><br> 归档</a></li><li class="menu-item menu-item-about"><a href="/about/" rel="section"><i class="menu-item-icon fa fa-fw fa-user"></i><br> 关于</a></li><li class="menu-item menu-item-search"><a href="javascript:;" class="popup-trigger"><i class="menu-item-icon fa fa-search fa-fw"></i><br> 搜索</a></li></ul><div class="site-search"><div class="popup search-popup local-search-popup"><div class="local-search-header clearfix"><span class="search-icon"><i class="fa fa-search"></i></span><span class="popup-btn-close"><i class="fa fa-times-circle"></i></span><div class="local-search-input-wrapper"> <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input"></div></div><div id="local-search-result"></div></div></div></nav></div></header><main id="main" class="main"><div class="main-inner"><div class="content-wrap"><div id="content" class="content"><div id="posts" class="posts-expand"><article class="post post-type-normal" itemscope itemtype="http://schema.org/Article"><div class="post-block"><link itemprop="mainEntityOfPage" href="http://king-xiyu.gitee.io/article/3d977fbc.html"><span hidden itemprop="author" itemscope itemtype="http://schema.org/Person"><meta itemprop="name" content="King-XiYu"><meta itemprop="description" content=""><meta itemprop="image" content="http://ww1.sinaimg.cn/large/007WurYGgy1ge8nxttd9nj302s02s0si.jpg"></span><span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization"><meta itemprop="name" content="It is written"></span><header class="post-header"><h1 class="post-title" itemprop="name headline">React Native -- 仿抖音APP开发</h1><div class="post-meta"><span class="post-time"><span class="post-meta-item-icon"><i class="fa fa-calendar-o"></i></span> <span class="post-meta-item-text">发表于</span> <time title="创建于" itemprop="dateCreated datePublished" datetime="2020-05-17T22:44:48+08:00">2020-05-17</time> <span class="post-meta-divider">|</span><span class="post-meta-item-icon"><i class="fa fa-calendar-check-o"></i></span> <span class="post-meta-item-text">更新于&#58;</span> <time title="更新于" itemprop="dateModified" datetime="2020-09-01T08:45:13+08:00">2020-09-01</time></span> <span class="post-category"><span class="post-meta-divider">|</span><span class="post-meta-item-icon"><i class="fa fa-folder-o"></i></span> <span class="post-meta-item-text">分类于</span> <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/%E6%8A%80%E6%9C%AF%E6%A0%88/" itemprop="url" rel="index"><span itemprop="name">技术栈</span></a></span> ， <span itemprop="about" itemscope itemtype="http://schema.org/Thing"><a href="/categories/%E6%8A%80%E6%9C%AF%E6%A0%88/ReactNative/" itemprop="url" rel="index"><span itemprop="name">ReactNative</span></a></span></span> <span class="post-comments-count"><span class="post-meta-divider">|</span><span class="post-meta-item-icon"><i class="fa fa-comment-o"></i></span><a href="/article/3d977fbc.html#comments" itemprop="discussionUrl"><span class="post-comments-count valine-comment-count" data-xid="/article/3d977fbc.html" itemprop="commentCount"></span></a></span> <span id="/article/3d977fbc.html" class="leancloud_visitors" data-flag-title="React Native -- 仿抖音APP开发"><span class="post-meta-divider">|</span><span class="post-meta-item-icon"><i class="fa fa-eye"></i></span> <span class="post-meta-item-text">阅读次数&#58;</span><span class="leancloud-visitors-count"></span></span><div class="post-wordcount"><span class="post-meta-item-icon"><i class="fa fa-file-word-o"></i></span> <span class="post-meta-item-text">字数统计&#58;</span> <span title="字数统计">8.7k 字</span> <span class="post-meta-divider">|</span><span class="post-meta-item-icon"><i class="fa fa-clock-o"></i></span> <span class="post-meta-item-text">阅读时长 &asymp;</span> <span title="阅读时长">36 分钟</span></div></div></header><div class="post-body" itemprop="articleBody"><p>抖音APP原型图地址：</p><p><a href="http://cloud.axureshop.com/S4UIH5/#id=a9fqgo&amp;p=app%E7%A7%BB%E5%8A%A8%E7%AB%AF&amp;sc=2&amp;dp=0&amp;fn=0" target="_blank" rel="noopener">http://cloud.axureshop.com/S4UIH5/#id=a9fqgo&amp;p=app%E7%A7%BB%E5%8A%A8%E7%AB%AF&amp;sc=2&amp;dp=0&amp;fn=0</a></p><p>码云：<a href="https://gitee.com/King-XiYu/rn-douyin-app" target="_blank" rel="noopener">https://gitee.com/King-XiYu/rn-douyin-app</a></p><a id="more"></a><br><h1 id="创建项目"><a href="#创建项目" class="headerlink" title="创建项目"></a>创建项目</h1><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npx react-native init rnDouyinApp</span><br></pre></td></tr></table></figure><h1 id="安装-React-Navigation"><a href="#安装-React-Navigation" class="headerlink" title="安装 React Navigation"></a>安装 React Navigation</h1><h2 id="安装基础包"><a href="#安装基础包" class="headerlink" title="安装基础包"></a>安装基础包</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn add @react-navigation/native</span><br></pre></td></tr></table></figure><h2 id="安装依赖包"><a href="#安装依赖包" class="headerlink" title="安装依赖包"></a>安装依赖包</h2><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn  add react-native-reanimated react-native-gesture-handler react-native-screens react-native-safe-area-context @react-native-community/masked-view</span><br></pre></td></tr></table></figure><h2 id="首页配置"><a href="#首页配置" class="headerlink" title="首页配置"></a>首页配置</h2><p>在首页（index.js）的第一行添加</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">import  &#39;react-native-gesture-handler&#39;;</span><br></pre></td></tr></table></figure><h2 id="安装导航器"><a href="#安装导航器" class="headerlink" title="安装导航器"></a>安装导航器</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">yarn add @react-navigation&#x2F;stack</span><br><span class="line">yarn add @react-navigation&#x2F;bottom-tabs</span><br></pre></td></tr></table></figure><h2 id="安装图标库"><a href="#安装图标库" class="headerlink" title="安装图标库"></a>安装图标库</h2><h3 id="安装包"><a href="#安装包" class="headerlink" title="安装包"></a>安装包</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn add react-native-vector-icons</span><br></pre></td></tr></table></figure><h3 id="配置"><a href="#配置" class="headerlink" title="配置"></a>配置</h3><p>在 Android 系统中要使用图标需要配置。</p><p>修改 <code>android/app/build.gradle</code> 文件，添加一行到最后：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">apply from: &quot;..&#x2F;..&#x2F;node_modules&#x2F;react-native-vector-icons&#x2F;fonts.gradle&quot;</span><br></pre></td></tr></table></figure><h2 id="安装-ViewPager"><a href="#安装-ViewPager" class="headerlink" title="安装 ViewPager"></a>安装 ViewPager</h2><p>可以实现屏幕滑动的库。</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn add @react-native-community&#x2F;viewpager</span><br></pre></td></tr></table></figure><h2 id="安装拍照录像包"><a href="#安装拍照录像包" class="headerlink" title="安装拍照录像包"></a>安装拍照录像包</h2><h3 id="安装包-1"><a href="#安装包-1" class="headerlink" title="安装包"></a>安装包</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn add react-native-image-crop-picker</span><br></pre></td></tr></table></figure><h3 id="配置1"><a href="#配置1" class="headerlink" title="配置1"></a>配置1</h3><p>修改 <code>android/build.gradle</code> 文件。<br>找到 <code>allprojects</code> 配置项，添加</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">allprojects &#123;</span><br><span class="line">    repositories &#123;</span><br><span class="line">      mavenLocal()</span><br><span class="line">      jcenter()</span><br><span class="line">      maven &#123; url &quot;$rootDir&#x2F;..&#x2F;node_modules&#x2F;react-native&#x2F;android&quot; &#125;</span><br><span class="line"></span><br><span class="line">      &#x2F;&#x2F; 添加这行</span><br><span class="line">      maven &#123; url &#39;https:&#x2F;&#x2F;maven.google.com&#39; &#125;</span><br><span class="line"></span><br><span class="line">      ...</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h3 id="配置2"><a href="#配置2" class="headerlink" title="配置2"></a>配置2</h3><p>修改 <code>android/app/build.gradle</code> 文件</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">android &#123;</span><br><span class="line">    ...</span><br><span class="line"></span><br><span class="line">    defaultConfig &#123;</span><br><span class="line">        ...</span><br><span class="line">        vectorDrawables.useSupportLibrary &#x3D; true</span><br><span class="line">        ...</span><br><span class="line">    &#125;</span><br><span class="line">    ...</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure><h3 id="配置3、添加权限"><a href="#配置3、添加权限" class="headerlink" title="配置3、添加权限"></a>配置3、添加权限</h3><p>修改 <code>app/src/main/AndroidManifest.xml</code> 文件。<br>添加三行</p><ul><li><code>&lt;uses-permission android:name=&quot;android.permission.CAMERA&quot;/&gt;</code></li><li><code>&lt;uses-feature android:name=&quot;android.hardware.camera&quot; android:required=&quot;false&quot; /&gt;</code></li><li><code>&lt;uses-feature android:name=&quot;android.hardware.camera.front&quot; android:required=&quot;false&quot; /&gt;</code></li></ul><h2 id="安装视频播放器"><a href="#安装视频播放器" class="headerlink" title="安装视频播放器"></a>安装视频播放器</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn add react-native-video</span><br></pre></td></tr></table></figure><h2 id="安装tabview"><a href="#安装tabview" class="headerlink" title="安装tabview"></a>安装tabview</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn add react-native-scrollable-tab-view</span><br></pre></td></tr></table></figure><br><h1 id="页面结构导航"><a href="#页面结构导航" class="headerlink" title="页面结构导航"></a>页面结构导航</h1><h2 id="创建页面结构"><a href="#创建页面结构" class="headerlink" title="创建页面结构"></a>创建页面结构</h2><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gevuzqrqh4j320612w7wh.jpg" alt="4c86f233d4a62838dfa255f188835546_2598x1400.png"></p><h2 id="创建导航器"><a href="#创建导航器" class="headerlink" title="创建导航器"></a>创建导航器</h2><p>我们需要使用导航器，把这些页面都连接起来。<br>导航器的关系：</p><ol><li>启动页 和 主页 是 <code>stack</code> 导航器</li><li>主页中的四个块是 <code>Bottom Tab</code> 导航器</li></ol><h3 id="引入导航容器"><a href="#引入导航容器" class="headerlink" title="引入导航容器"></a>引入导航容器</h3><p>所有的导航要通过容器包起来了。</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">import  &#123;  NavigationContainer  &#125;  from  &#39;@react-navigation&#x2F;native&#39;;</span><br></pre></td></tr></table></figure><p>App.js 包起来所有的文件。</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; StyleSheet, Text, View &#125; <span class="keyword">from</span> <span class="string">'react-native'</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; NavigationContainer &#125; <span class="keyword">from</span> <span class="string">'@react-navigation/native'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> App = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    &lt;NavigationContainer&gt;</span><br><span class="line">      &lt;Text&gt;你好~！！&lt;<span class="regexp">/Text&gt;</span></span><br><span class="line"><span class="regexp">    &lt;/</span>NavigationContainer&gt;</span><br><span class="line">  );</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> App;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> styles = StyleSheet.create(&#123;&#125;);</span><br></pre></td></tr></table></figure><p>App.js 创建 Stack 导航器管理封面页和主页</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gevvzko7b5j30xp0nzgqj.jpg" alt="Snipaste_2020-05-17_23-56-06.png"></p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; StyleSheet, Text, View &#125; <span class="keyword">from</span> <span class="string">'react-native'</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; NavigationContainer &#125; <span class="keyword">from</span> <span class="string">'@react-navigation/native'</span>;</span><br><span class="line"><span class="keyword">import</span> &#123; createStackNavigator &#125; <span class="keyword">from</span> <span class="string">'@react-navigation/stack'</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 创建 Stack 导航器</span></span><br><span class="line"><span class="keyword">const</span> SplashNavigator = createStackNavigator();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 管理封面页和主页</span></span><br><span class="line"><span class="keyword">import</span> SplashPage <span class="keyword">from</span> <span class="string">'./pages/Splash'</span></span><br><span class="line"><span class="keyword">import</span> IndexPage <span class="keyword">from</span> <span class="string">'./pages/main/Index'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> App = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">  <span class="keyword">return</span> (</span><br><span class="line">    &lt;NavigationContainer&gt;</span><br><span class="line">      &lt;SplashNavigator.Navigator headerMode=<span class="string">"none"</span>&gt;</span><br><span class="line">        &lt;SplashNavigator.Screen name=<span class="string">"Splash"</span> component=&#123;SplashPage&#125; /&gt;</span><br><span class="line">        &lt;SplashNavigator.Screen name=<span class="string">"Index"</span> component=&#123;IndexPage&#125; /&gt;</span><br><span class="line">      &lt;<span class="regexp">/SplashNavigator.Navigator&gt;</span></span><br><span class="line"><span class="regexp">    &lt;/</span>NavigationContainer&gt;</span><br><span class="line">  );</span><br><span class="line">&#125;;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> App;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> styles = StyleSheet.create(&#123;&#125;);</span><br></pre></td></tr></table></figure><h3 id="创建底部导航器把主页面中四大块页面管理起来"><a href="#创建底部导航器把主页面中四大块页面管理起来" class="headerlink" title="创建底部导航器把主页面中四大块页面管理起来"></a>创建底部导航器把主页面中四大块页面管理起来</h3><p>要主页面创建底部导航器管理四大块页面。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gevw8ejj3cj310y0o5jwu.jpg" alt="Snipaste_2020-05-18_00-04-53.png"></p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; StyleSheet, Text, View &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"><span class="keyword">import</span> &#123; createBottomTabNavigator &#125; <span class="keyword">from</span> <span class="string">'@react-navigation/bottom-tabs'</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 创建底部导航器</span></span><br><span class="line"><span class="keyword">const</span> IndexBottomNavigator = createBottomTabNavigator();</span><br><span class="line"></span><br><span class="line"><span class="comment">// 导入四个页面</span></span><br><span class="line"><span class="keyword">import</span> IndexPage <span class="keyword">from</span> <span class="string">'./index/Index'</span></span><br><span class="line"><span class="keyword">import</span> CityPage <span class="keyword">from</span> <span class="string">'./city/Index'</span></span><br><span class="line"><span class="keyword">import</span> MessagePage <span class="keyword">from</span> <span class="string">'./message/Index'</span></span><br><span class="line"><span class="keyword">import</span> MePage <span class="keyword">from</span> <span class="string">'./me/Index'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> Index = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;IndexBottomNavigator.Navigator&gt;</span><br><span class="line">            &lt;IndexBottomNavigator.Screen name=<span class="string">"Main"</span> component=&#123;IndexPage&#125; /&gt;</span><br><span class="line">            &lt;IndexBottomNavigator.Screen name=<span class="string">"City"</span> component=&#123;CityPage&#125; /&gt;</span><br><span class="line">            &lt;IndexBottomNavigator.Screen name=<span class="string">"Message"</span> component=&#123;MessagePage&#125; /&gt;</span><br><span class="line">            &lt;IndexBottomNavigator.Screen name=<span class="string">"Me"</span> component=&#123;MePage&#125; /&gt;</span><br><span class="line">        &lt;<span class="regexp">/IndexBottomNavigator.Navigator&gt;</span></span><br><span class="line"><span class="regexp">    )</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">export default Index</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">const styles = StyleSheet.create(&#123;&#125;)</span></span><br></pre></td></tr></table></figure><h3 id="在首页中再使用-Stack-导航器管理子页面"><a href="#在首页中再使用-Stack-导航器管理子页面" class="headerlink" title="在首页中再使用 Stack 导航器管理子页面"></a>在首页中再使用 Stack 导航器管理子页面</h3><p>在主页中又可以分为搜索页、视频页、主播个人主页等子页面，需要管理起来：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gevwhcr77yj30yk0ox0x6.jpg" alt="4c86f233d4a62838dfa255f188835546_2598x1400.png"></p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; createStackNavigator &#125; <span class="keyword">from</span> <span class="string">'@react-navigation/stack'</span></span><br><span class="line"></span><br><span class="line"><span class="comment">// 引入页面</span></span><br><span class="line"><span class="keyword">import</span> Video <span class="keyword">from</span> <span class="string">'./Video'</span></span><br><span class="line"><span class="keyword">import</span> Room <span class="keyword">from</span> <span class="string">'./Room'</span></span><br><span class="line"><span class="keyword">import</span> Search <span class="keyword">from</span> <span class="string">'./Search'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> IndexStackNavigator = createStackNavigator();</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> Index = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;IndexStackNavigator.Navigator&gt;</span><br><span class="line">            &lt;IndexStackNavigator.Screen </span><br><span class="line">            name=<span class="string">"Video"</span> </span><br><span class="line">            component=&#123;Video&#125;</span><br><span class="line">            options=&#123;&#123;</span><br><span class="line">                headerShown: <span class="literal">false</span>,</span><br><span class="line">            &#125;&#125;</span><br><span class="line">             /&gt;</span><br><span class="line">            &lt;IndexStackNavigator.Screen name=<span class="string">"Room"</span> component=&#123;Room&#125; /&gt;</span><br><span class="line">            &lt;IndexStackNavigator.Screen name=<span class="string">"Search"</span> component=&#123;Search&#125; /&gt;</span><br><span class="line">        &lt;<span class="regexp">/IndexStackNavigator.Navigator&gt;</span></span><br><span class="line"><span class="regexp">    )</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">export default Index</span></span><br></pre></td></tr></table></figure><h1 id="封面页"><a href="#封面页" class="headerlink" title="封面页"></a>封面页</h1><h2 id="下载图片"><a href="#下载图片" class="headerlink" title="下载图片"></a>下载图片</h2><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gevwn50c74j31250nbdjj.jpg" alt="Snipaste_2020-05-18_00-18-53.png"></p><h2 id="编写-Splash-页"><a href="#编写-Splash-页" class="headerlink" title="编写 Splash 页"></a>编写 Splash 页</h2><p>Splash 页面中延迟3秒跳转到首页</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gevwzxc2uvj30vt0qqjvk.jpg" alt="Snipaste_2020-05-18_00-31-23.png"></p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React, &#123; useEffect &#125; <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; StyleSheet, Image, StatusBar, View &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> Splash = <span class="function">(<span class="params">&#123; navigation &#125;</span>) =&gt;</span> &#123;</span><br><span class="line"></span><br><span class="line">    useEffect(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">        setTimeout(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">            <span class="comment">// replace: 销毁当前页，跳转到下一个页面</span></span><br><span class="line">            navigation.replace(<span class="string">'Index'</span>)</span><br><span class="line">        &#125;, <span class="number">5000</span>)</span><br><span class="line">    &#125;, [navigation])</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;View style=&#123;styles.splash&#125;&gt;</span><br><span class="line">            &lt;StatusBar hidden=&#123;<span class="literal">true</span>&#125; /&gt;</span><br><span class="line">            &lt;Image source=&#123;<span class="built_in">require</span>(<span class="string">'../images/splash.jpg'</span>)&#125; /&gt;</span><br><span class="line">        &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">    )</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">export default Splash</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">const styles = StyleSheet.create(&#123;</span></span><br><span class="line"><span class="regexp">    splash: &#123;</span></span><br><span class="line"><span class="regexp">        flex: 1,</span></span><br><span class="line"><span class="regexp">        alignItems: 'center',</span></span><br><span class="line"><span class="regexp">        justifyContent: 'center',</span></span><br><span class="line"><span class="regexp">        backgroundColor: '#1C0E1B',</span></span><br><span class="line"><span class="regexp">    &#125;</span></span><br><span class="line"><span class="regexp">&#125;)</span></span><br></pre></td></tr></table></figure><br><h1 id="首页"><a href="#首页" class="headerlink" title="首页"></a>首页</h1><h2 id="视频播放页"><a href="#视频播放页" class="headerlink" title="视频播放页"></a>视频播放页</h2><p>根据以下需求写组件</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gewwnmtfhnj30bm0n54f8.jpg" alt="image.png"></p><h3 id="制作图标按钮组件"><a href="#制作图标按钮组件" class="headerlink" title="制作图标按钮组件"></a>制作图标按钮组件</h3><p>因为项目中很多按钮都是一个图标或者汉字，但是默认是 RN 中只有 <code>Button</code> 组件这一种按钮，完全不够用，所以我们需要首先封装几个按钮组件。</p><h4 id="图标按钮"><a href="#图标按钮" class="headerlink" title="图标按钮"></a>图标按钮</h4><p>因为组件可能比较多，所以需要创建目录分类管理组件：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gewuxr1z7fj30tr0m8q5y.jpg" alt="image.png"></p><p>IconButton.js</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; TouchableWithoutFeedback &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"><span class="keyword">import</span> Icon <span class="keyword">from</span> <span class="string">'react-native-vector-icons/MaterialIcons'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> IconButton = <span class="function">(<span class="params">&#123; onPress, name, size, color &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;TouchableWithoutFeedback onPress=&#123;onPress&#125;&gt;</span><br><span class="line">            &lt;Icon name=&#123;name&#125; size=&#123;size&#125; color=&#123;color&#125; /&gt;</span><br><span class="line">        &lt;<span class="regexp">/TouchableWithoutFeedback&gt;</span></span><br><span class="line"><span class="regexp">    )</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">/</span><span class="regexp">/ 设置默认属性值</span></span><br><span class="line"><span class="regexp">IconButton.defaultProps = &#123;</span></span><br><span class="line"><span class="regexp">    size: 30,</span></span><br><span class="line"><span class="regexp">    color: 'black'</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">export default IconButton</span></span><br></pre></td></tr></table></figure><h3 id="头像组件"><a href="#头像组件" class="headerlink" title="头像组件"></a>头像组件</h3><h4 id="静态头像组件"><a href="#静态头像组件" class="headerlink" title="静态头像组件"></a>静态头像组件</h4><p>编写一个头像组件，可以控制尺寸和边框：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1geww1u5fhej30ro0m9q5t.jpg" alt="image.png"></p><p>Avatar.js</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; Image &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> Avatar = <span class="function">(<span class="params">&#123; uri, size, border &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;Image source=&#123;&#123; uri &#125;&#125; style=&#123;&#123;</span><br><span class="line">            borderColor: <span class="string">'black'</span>,</span><br><span class="line">            borderWidth: border,</span><br><span class="line">            borderRadius: size === <span class="string">'big'</span> ? <span class="number">50</span> : <span class="number">25</span>,</span><br><span class="line">            width: size === <span class="string">'big'</span> ? <span class="number">100</span> : <span class="number">50</span>,</span><br><span class="line">            height: size === <span class="string">'big'</span> ? <span class="number">100</span> : <span class="number">50</span>,</span><br><span class="line">        &#125;&#125; /&gt;</span><br><span class="line">    )</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 设置默认属性值</span></span><br><span class="line">Avatar.defaultProps = &#123;</span><br><span class="line">    size: <span class="string">'sm'</span>,</span><br><span class="line">    border: <span class="number">0</span>,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> Avatar</span><br></pre></td></tr></table></figure><h4 id="旋转的头像组件"><a href="#旋转的头像组件" class="headerlink" title="旋转的头像组件"></a>旋转的头像组件</h4><p>有时头像需要旋转功能。<br>可以使用 RN 中提供的 <code>Animated</code> 组件实现动画效果：</p><p>RotateAvatar.js</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React, &#123; useState, useEffect &#125; <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; Animated, Easing &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> RotateAvatar = <span class="function">(<span class="params">&#123; uri, size, border, borderColor &#125;</span>) =&gt;</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 动画的变量</span></span><br><span class="line">    <span class="keyword">const</span> [rotate] = useState(<span class="keyword">new</span> Animated.Value(<span class="number">0</span>))</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 组件加载时就启动</span></span><br><span class="line">    useEffect(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">        <span class="comment">// 定义一个动画函数</span></span><br><span class="line">        <span class="function"><span class="keyword">function</span> <span class="title">move</span>(<span class="params"></span>) </span>&#123;</span><br><span class="line">            <span class="comment">// 创建动画并启动</span></span><br><span class="line">            Animated.timing(rotate, &#123;</span><br><span class="line">                toValue: <span class="number">1</span>, <span class="comment">// 变化到的目标值</span></span><br><span class="line">                duration: <span class="number">4000</span>, <span class="comment">// 时间，单位： 毫秒</span></span><br><span class="line">                useNativeDriver: <span class="literal">true</span>, <span class="comment">// 是否启用原生驱动</span></span><br><span class="line">                easing: Easing.linear, <span class="comment">// 均速动画</span></span><br><span class="line">            &#125;).start(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">                <span class="comment">// 这个回调函数会在每次动画执行完之后调用</span></span><br><span class="line">                <span class="comment">// 将值初始化回 0</span></span><br><span class="line">                rotate.setValue(<span class="number">0</span>);</span><br><span class="line">                <span class="comment">// 再启动动画</span></span><br><span class="line">                move();</span><br><span class="line">            &#125;)</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="comment">// 调用函数启动动画</span></span><br><span class="line">        move();</span><br><span class="line">    &#125;, [rotate])</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;Animated.Image</span><br><span class="line">            source=&#123;&#123; uri &#125;&#125;</span><br><span class="line">            style=&#123;&#123;</span><br><span class="line">                borderColor,</span><br><span class="line">                borderWidth: border,</span><br><span class="line">                borderRadius: size === <span class="string">'big'</span> ? <span class="number">50</span> : <span class="number">25</span>,</span><br><span class="line">                width: size === <span class="string">'big'</span> ? <span class="number">100</span> : <span class="number">50</span>,</span><br><span class="line">                height: size === <span class="string">'big'</span> ? <span class="number">100</span> : <span class="number">50</span>,</span><br><span class="line">                transform: [</span><br><span class="line">                    &#123;</span><br><span class="line">                        rotate: rotate.interpolate(&#123;</span><br><span class="line">                            inputRange: [<span class="number">0</span>, <span class="number">1</span>], <span class="comment">// 输入变量的变化范围</span></span><br><span class="line">                            outputRange: [<span class="string">'0deg'</span>, <span class="string">'360deg'</span>],    <span class="comment">// 映射的实际输出的值的范围</span></span><br><span class="line">                        &#125;)</span><br><span class="line">                    &#125;</span><br><span class="line">                ]</span><br><span class="line">            &#125;&#125;</span><br><span class="line">        /&gt;</span><br><span class="line">    )</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 设置默认属性值</span></span><br><span class="line">RotateAvatar.defaultProps = &#123;</span><br><span class="line">    size: <span class="string">'sm'</span>,</span><br><span class="line">    border: <span class="number">0</span>,</span><br><span class="line">    borderColor: <span class="string">'black'</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> RotateAvatar</span><br></pre></td></tr></table></figure><h3 id="红心点赞组件"><a href="#红心点赞组件" class="headerlink" title="红心点赞组件"></a>红心点赞组件</h3><h4 id="先下载两张图片"><a href="#先下载两张图片" class="headerlink" title="先下载两张图片"></a>先下载两张图片</h4><p>可以到 <a href="https://www.iconfont.cn/" target="_blank" rel="noopener">https://www.iconfont.cn/</a> 下载两个心的图片。（红心、和白心）。<br><img src="https://img.kancloud.cn/a7/df/a7df5e1ff65d2b3e39471d8f8975d33e_352x146.png" alt="img"></p><h3 id="编写红心点赞组件"><a href="#编写红心点赞组件" class="headerlink" title="编写红心点赞组件"></a>编写红心点赞组件</h3><p>/components/button/HeartBtn.js</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React, &#123; useState, useMemo &#125; <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; View, Text, TouchableNativeFeedback, Animated &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">import</span> rh <span class="keyword">from</span> <span class="string">'../../images/heart-r.png'</span>;</span><br><span class="line"><span class="keyword">import</span> wh <span class="keyword">from</span> <span class="string">'../../images/heart-w.png'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> HeartBtn = <span class="function">(<span class="params">&#123; number &#125;</span>) =&gt;</span> &#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 当前的心， false：白  true：红色</span></span><br><span class="line">    <span class="keyword">const</span> [heart, setHeart] = useState(<span class="literal">false</span>)</span><br><span class="line">    <span class="comment">// 定义心缩放的值</span></span><br><span class="line">    <span class="keyword">const</span> [scale] = useState(<span class="keyword">new</span> Animated.Value(<span class="number">0</span>))</span><br><span class="line"></span><br><span class="line">    <span class="comment">// 创建动画</span></span><br><span class="line">    <span class="keyword">const</span> ani = useMemo(<span class="function"><span class="params">()</span> =&gt;</span></span><br><span class="line">        Animated.timing(scale, &#123;</span><br><span class="line">            toValue: <span class="number">3</span>,</span><br><span class="line">            duration: <span class="number">800</span>,</span><br><span class="line">            useNativeDriver: <span class="literal">true</span>,</span><br><span class="line">        &#125;), [scale])</span><br><span class="line"></span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;View style=&#123;&#123; <span class="attr">flexDirection</span>: <span class="string">'column'</span> &#125;&#125;&gt;</span><br><span class="line">            &lt;TouchableNativeFeedback</span><br><span class="line">                onPress=&#123;() =&gt; &#123;</span><br><span class="line">                    <span class="comment">// 启动动画</span></span><br><span class="line">                    ani.start(<span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">                        <span class="comment">// 动画执行完之后初始值重置为 0</span></span><br><span class="line">                        scale.setValue(<span class="number">0</span>)</span><br><span class="line">                    &#125;);</span><br><span class="line">                    <span class="comment">// 切换心</span></span><br><span class="line">                    setHeart(!heart);</span><br><span class="line">                &#125;&#125;</span><br><span class="line">            &gt;</span><br><span class="line">                &lt;Animated.Image</span><br><span class="line">                    source=&#123;heart ? rh : wh&#125;</span><br><span class="line">                    style=&#123;&#123;</span><br><span class="line">                        transform: [</span><br><span class="line">                            &#123;</span><br><span class="line">                                scale: scale.interpolate(&#123;</span><br><span class="line">                                    inputRange: [<span class="number">0</span>, <span class="number">1</span>, <span class="number">2</span>, <span class="number">3</span>],</span><br><span class="line">                                    outputRange: [<span class="number">1</span>, <span class="number">0.6</span>, <span class="number">1.4</span>, <span class="number">1</span>]</span><br><span class="line">                                &#125;)</span><br><span class="line">                            &#125;</span><br><span class="line">                        ]</span><br><span class="line">                    &#125;&#125;</span><br><span class="line">                /&gt;</span><br><span class="line"></span><br><span class="line">            &lt;<span class="regexp">/TouchableNativeFeedback&gt;</span></span><br><span class="line"><span class="regexp">            &lt;Text style=&#123;&#123;</span></span><br><span class="line"><span class="regexp">                color: 'white',</span></span><br><span class="line"><span class="regexp">                fontWeight: 'bold',</span></span><br><span class="line"><span class="regexp">                fontSize: 16,</span></span><br><span class="line"><span class="regexp">            &#125;&#125;&gt;</span></span><br><span class="line"><span class="regexp">                &#123;number&#125;</span></span><br><span class="line"><span class="regexp">            &lt;/</span>Text&gt;</span><br><span class="line">        &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">    )</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">export default HeartBtn</span></span><br></pre></td></tr></table></figure><h2 id="带文本的图标按钮组件"><a href="#带文本的图标按钮组件" class="headerlink" title="带文本的图标按钮组件"></a>带文本的图标按钮组件</h2><p>/components/button/IconTextButton.js</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; Text &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"><span class="keyword">import</span> IconButton <span class="keyword">from</span> <span class="string">'./IconButton'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> IconTextButton = <span class="function">(<span class="params">&#123; text, onPress, name, size, color &#125;</span>) =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;&gt;</span><br><span class="line">            &lt;IconButton name=&#123;name&#125; onPress=&#123;onPress&#125; color=&#123;color&#125; size=&#123;size&#125; /&gt;</span><br><span class="line">            &lt;Text style=&#123;&#123;</span><br><span class="line">                color: <span class="string">'white'</span>,</span><br><span class="line">                fontWeight: <span class="string">'bold'</span>,</span><br><span class="line">                fontSize: <span class="number">16</span>,</span><br><span class="line">            &#125;&#125;&gt;&#123;text&#125;&lt;<span class="regexp">/Text&gt;</span></span><br><span class="line"><span class="regexp">        &lt;/</span>&gt;</span><br><span class="line">    )</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="comment">// 设置默认属性值</span></span><br><span class="line">IconTextButton.defaultProps = &#123;</span><br><span class="line">    color: <span class="string">'white'</span>,</span><br><span class="line">    size: <span class="number">35</span>,</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> IconTextButton</span><br></pre></td></tr></table></figure><p>组件写好之后，可以用来制作评论和分享的按钮。</p><p>以上组件制作完成后的效果图：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gex13aqqgvj30bl0oqq4g.jpg" alt="image.png"></p><h3 id="全屏的视频播放组件"><a href="#全屏的视频播放组件" class="headerlink" title="全屏的视频播放组件"></a>全屏的视频播放组件</h3><h4 id="全屏视频播放组件01-全屏播放"><a href="#全屏视频播放组件01-全屏播放" class="headerlink" title="全屏视频播放组件01-全屏播放"></a>全屏视频播放组件01-全屏播放</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gezb3ow8yej310c0qw436.jpg" alt="image.png"></p><h4 id="全屏视频播放组件02-右侧的图标按钮"><a href="#全屏视频播放组件02-右侧的图标按钮" class="headerlink" title="全屏视频播放组件02-右侧的图标按钮"></a>全屏视频播放组件02-右侧的图标按钮</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gezbit0lscj30uu0t7qfm.jpg" alt="image.png"></p><h4 id="全屏视频播放组件03-评论框"><a href="#全屏视频播放组件03-评论框" class="headerlink" title="全屏视频播放组件03-评论框"></a>全屏视频播放组件03-评论框</h4><p>打开、关闭评论框的原理就是修改评论框的 height 属性，0%时关闭，85%时打开。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gezbqx3zrvj30p20ob0vv.jpg" alt="image.png"></p><p>css样式</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gezbrcc5q1j30a90cu74k.jpg" alt="image.png"></p><p>全屏视频播放组件的总代码</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br><span class="line">134</span><br><span class="line">135</span><br><span class="line">136</span><br><span class="line">137</span><br><span class="line">138</span><br><span class="line">139</span><br><span class="line">140</span><br><span class="line">141</span><br><span class="line">142</span><br><span class="line">143</span><br><span class="line">144</span><br><span class="line">145</span><br><span class="line">146</span><br><span class="line">147</span><br><span class="line">148</span><br><span class="line">149</span><br><span class="line">150</span><br><span class="line">151</span><br><span class="line">152</span><br><span class="line">153</span><br><span class="line">154</span><br><span class="line">155</span><br><span class="line">156</span><br><span class="line">157</span><br><span class="line">158</span><br><span class="line">159</span><br><span class="line">160</span><br><span class="line">161</span><br><span class="line">162</span><br><span class="line">163</span><br><span class="line">164</span><br><span class="line">165</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; StyleSheet, View, Text, StatusBar, FlatList, Animated, &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"><span class="keyword">import</span> Video <span class="keyword">from</span> <span class="string">'react-native-video'</span></span><br><span class="line"><span class="comment">// 引入组件</span></span><br><span class="line"><span class="keyword">import</span> Avatar <span class="keyword">from</span> <span class="string">'../avatar/Avatar'</span></span><br><span class="line"><span class="keyword">import</span> HeartBtn <span class="keyword">from</span> <span class="string">'../button/HeartBtn'</span></span><br><span class="line"><span class="keyword">import</span> IconTextButton <span class="keyword">from</span> <span class="string">'../button/IconTextButton'</span></span><br><span class="line"><span class="keyword">import</span> RotateAvatar <span class="keyword">from</span> <span class="string">'../avatar/RotateAvatar'</span></span><br><span class="line"><span class="keyword">import</span> IconButton <span class="keyword">from</span> <span class="string">'../button/IconButton'</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> VideoPlay = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 定义评论框的高度</span></span><br><span class="line">    <span class="keyword">const</span> [commentHeight] = React.useState(<span class="keyword">new</span> Animated.Value(<span class="number">0</span>));</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;View style=&#123;&#123; <span class="attr">flex</span>: <span class="number">1</span> &#125;&#125;&gt;</span><br><span class="line">            &#123;<span class="comment">/* 顶部状态栏 */</span>&#125;</span><br><span class="line">            &lt;StatusBar</span><br><span class="line">                translucent=&#123;<span class="literal">true</span>&#125;</span><br><span class="line">                backgroundColor=<span class="string">"rgba(0,0,0,0)"</span></span><br><span class="line">                barStyle=<span class="string">"dark-content"</span></span><br><span class="line">            /&gt;</span><br><span class="line">            &#123;<span class="comment">/* 视频播放 */</span>&#125;</span><br><span class="line">            &lt;Video</span><br><span class="line">                resizeMode=<span class="string">"cover"</span></span><br><span class="line">                style=&#123;styles.video&#125;</span><br><span class="line">                <span class="comment">// 视频地址</span></span><br><span class="line">                source=&#123;&#123; <span class="attr">uri</span>: <span class="string">'http://player.alicdn.com/video/editor.mp4'</span> &#125;&#125;</span><br><span class="line">                <span class="comment">// poster 视频未加载出了前先显示该图片</span></span><br><span class="line">                poster=<span class="string">"https://img12.360buyimg.com/pop/s1180x940_jfs/t1/121656/1/2153/65912/5ec388e3E3581fdfb/44f175e004088ceb.jpg.webp"</span></span><br><span class="line">                posterResizeMode=<span class="string">"cover"</span></span><br><span class="line">            /&gt;</span><br><span class="line">            &#123;<span class="comment">/* 图标按钮 */</span>&#125;</span><br><span class="line">            &lt;View style=&#123;styles.btns&#125;&gt;</span><br><span class="line">                &lt;View style=&#123;styles.btnItem&#125;&gt;</span><br><span class="line">                    &lt;Avatar uri=<span class="string">"http://ww1.sinaimg.cn/large/007WurYGgy1ge8nxttd9nj302s02s0si.jpg"</span> /&gt;</span><br><span class="line">                &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">                &lt;View style=&#123;styles.btnItem&#125;&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;HeartBtn number="66.6w" /</span>&gt;</span><br><span class="line">                &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">                &lt;View style=&#123;styles.btnItem&#125;&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;IconTextButton</span></span><br><span class="line"><span class="regexp">                        name="comment"</span></span><br><span class="line"><span class="regexp">                        text="9850"</span></span><br><span class="line"><span class="regexp">                        onPress=&#123;() =&gt; &#123;</span></span><br><span class="line"><span class="regexp">                            Animated.timing(commentHeight, &#123;</span></span><br><span class="line"><span class="regexp">                                toValue: 1,</span></span><br><span class="line"><span class="regexp">                                duration: 200,</span></span><br><span class="line"><span class="regexp">                                useNativeDriver: false,</span></span><br><span class="line"><span class="regexp">                            &#125;).start();</span></span><br><span class="line"><span class="regexp">                        &#125;&#125;</span></span><br><span class="line"><span class="regexp">                    /</span>&gt;</span><br><span class="line">                &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">                &lt;View style=&#123;styles.btnItem&#125;&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;IconTextButton name="share" text="4399" /</span>&gt;</span><br><span class="line">                &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">                &lt;View style=&#123;styles.btnItem&#125;&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;RotateAvatar</span></span><br><span class="line"><span class="regexp">                        size="sm"</span></span><br><span class="line"><span class="regexp">                        border=&#123;10&#125;</span></span><br><span class="line"><span class="regexp">                        uri="http:/</span><span class="regexp">/ww1.sinaimg.cn/</span>large/<span class="number">007</span>WurYGgy1ge8nxttd9nj302s02s0si.jpg<span class="string">"</span></span><br><span class="line"><span class="string">                    /&gt;</span></span><br><span class="line"><span class="string">                &lt;/View&gt;</span></span><br><span class="line"><span class="string">            &lt;/View&gt;</span></span><br><span class="line"><span class="string">            &#123;/* 评论框 */&#125;</span></span><br><span class="line"><span class="string">            &lt;Animated.View</span></span><br><span class="line"><span class="string">                style=&#123;[</span></span><br><span class="line"><span class="string">                    styles.comment,</span></span><br><span class="line"><span class="string">                    &#123;</span></span><br><span class="line"><span class="string">                        height: commentHeight.interpolate(&#123;</span></span><br><span class="line"><span class="string">                            inputRange: [0, 1],</span></span><br><span class="line"><span class="string">                            outputRange: ['0%', '85%'],</span></span><br><span class="line"><span class="string">                        &#125;),</span></span><br><span class="line"><span class="string">                    &#125;,</span></span><br><span class="line"><span class="string">                ]&#125;&gt;</span></span><br><span class="line"><span class="string">                &#123;/* 关闭按钮、数量 */&#125;</span></span><br><span class="line"><span class="string">                &lt;View style=&#123;styles.commentHeader&#125;&gt;</span></span><br><span class="line"><span class="string">                    &lt;Text style=&#123;styles.commentText&#125;&gt;15条评论&lt;/Text&gt;</span></span><br><span class="line"><span class="string">                    &lt;IconButton</span></span><br><span class="line"><span class="string">                        name="</span>close<span class="string">"</span></span><br><span class="line"><span class="string">                        color="</span>white<span class="string">"</span></span><br><span class="line"><span class="string">                        size=&#123;25&#125;</span></span><br><span class="line"><span class="string">                        onPress=&#123;() =&gt; &#123;</span></span><br><span class="line"><span class="string">                            Animated.timing(commentHeight, &#123;</span></span><br><span class="line"><span class="string">                                toValue: 0,</span></span><br><span class="line"><span class="string">                                duration: 200,</span></span><br><span class="line"><span class="string">                                useNativeDriver: false,</span></span><br><span class="line"><span class="string">                            &#125;).start();</span></span><br><span class="line"><span class="string">                        &#125;&#125;</span></span><br><span class="line"><span class="string">                    /&gt;</span></span><br><span class="line"><span class="string">                &lt;/View&gt;</span></span><br><span class="line"><span class="string">                &#123;/* 评论列表 */&#125;</span></span><br><span class="line"><span class="string">                &lt;FlatList</span></span><br><span class="line"><span class="string">                    data=&#123;[1, 2, 3, 4, 5, 6, 7, 8, 9]&#125;</span></span><br><span class="line"><span class="string">                    keyExtractor=&#123;(item) =&gt; item.toString()&#125;</span></span><br><span class="line"><span class="string">                    renderItem=&#123;() =&gt; &lt;CommentItem /&gt;&#125;</span></span><br><span class="line"><span class="string">                /&gt;</span></span><br><span class="line"><span class="string">            &lt;/Animated.View&gt;</span></span><br><span class="line"><span class="string">        &lt;/View&gt;</span></span><br><span class="line"><span class="string">    )</span></span><br><span class="line"><span class="string">&#125;</span></span><br><span class="line"><span class="string"></span></span><br><span class="line"><span class="string">// 评论条目</span></span><br><span class="line"><span class="string">function CommentItem() &#123;</span></span><br><span class="line"><span class="string">    return (</span></span><br><span class="line"><span class="string">        &lt;View style=&#123;styles.commentItem&#125;&gt;</span></span><br><span class="line"><span class="string">            &#123;/* 头像 */&#125;</span></span><br><span class="line"><span class="string">            &lt;Avatar uri="</span>https:<span class="comment">//dss0.bdstatic.com/7Ls0a8Sm1A5BphGlnYG/sys/portrait/item/netdisk.1.3736c73e.iE-nqUKn1Z00_L7Fx2v8uQ.jpg" /&gt;</span></span><br><span class="line">            &#123;<span class="comment">/* 评论的内容 */</span>&#125;</span><br><span class="line">            &#123;<span class="comment">/* 评论的内容 */</span>&#125;</span><br><span class="line">            &lt;View style=&#123;&#123; <span class="attr">flex</span>: <span class="number">1</span>, <span class="attr">paddingLeft</span>: <span class="number">10</span>, <span class="attr">paddingRight</span>: <span class="number">10</span> &#125;&#125;&gt;</span><br><span class="line">                &lt;Text style=&#123;&#123; <span class="attr">color</span>: <span class="string">'white'</span>, <span class="attr">fontWeight</span>: <span class="string">'bold'</span> &#125;&#125;&gt;K先生&lt;<span class="regexp">/Text&gt;</span></span><br><span class="line"><span class="regexp">                &lt;Text style=&#123;&#123; color: 'white' &#125;&#125;&gt;</span></span><br><span class="line"><span class="regexp">                    阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴阿巴</span></span><br><span class="line"><span class="regexp">                &lt;/</span>Text&gt;</span><br><span class="line">            &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">            &#123;/</span>* 心 *<span class="regexp">/&#125;</span></span><br><span class="line"><span class="regexp">            &lt;HeartBtn number="66.6w" /</span>&gt;</span><br><span class="line">        &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">    )</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">export default VideoPlay</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">const styles = StyleSheet.create(&#123;</span></span><br><span class="line"><span class="regexp">    video: &#123;</span></span><br><span class="line"><span class="regexp">        position: 'absolute',</span></span><br><span class="line"><span class="regexp">        left: 0,</span></span><br><span class="line"><span class="regexp">        top: 0,</span></span><br><span class="line"><span class="regexp">        bottom: 0,</span></span><br><span class="line"><span class="regexp">        right: 0,</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp">    btns: &#123;</span></span><br><span class="line"><span class="regexp">        position: 'absolute',</span></span><br><span class="line"><span class="regexp">        right: 10,</span></span><br><span class="line"><span class="regexp">        bottom: 10,</span></span><br><span class="line"><span class="regexp">        alignItems: 'center',</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp">    btnItem: &#123;</span></span><br><span class="line"><span class="regexp">        marginTop: 20,</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp">    comment: &#123;</span></span><br><span class="line"><span class="regexp">        position: 'absolute',</span></span><br><span class="line"><span class="regexp">        bottom: 0,</span></span><br><span class="line"><span class="regexp">        width: '100%',</span></span><br><span class="line"><span class="regexp">        backgroundColor: 'rgba(0,0,0,0.8)',</span></span><br><span class="line"><span class="regexp">        borderTopLeftRadius: 15,</span></span><br><span class="line"><span class="regexp">        borderTopRightRadius: 15,</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp">    commentHeader: &#123;</span></span><br><span class="line"><span class="regexp">        flexDirection: 'row',</span></span><br><span class="line"><span class="regexp">        alignItems: 'center',</span></span><br><span class="line"><span class="regexp">        padding: 10,</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp">    commentText: &#123;</span></span><br><span class="line"><span class="regexp">        color: 'white',</span></span><br><span class="line"><span class="regexp">        alignItems: 'center',</span></span><br><span class="line"><span class="regexp">        flex: 1,</span></span><br><span class="line"><span class="regexp">        textAlign: 'center',</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp">    commentItem: &#123;</span></span><br><span class="line"><span class="regexp">        flexDirection: 'row',</span></span><br><span class="line"><span class="regexp">        alignItems: 'center',</span></span><br><span class="line"><span class="regexp">        padding: 10,</span></span><br><span class="line"><span class="regexp">    &#125;,</span></span><br><span class="line"><span class="regexp">&#125;)</span></span><br></pre></td></tr></table></figure><br><h2 id="抖音底部导航栏"><a href="#抖音底部导航栏" class="headerlink" title="抖音底部导航栏"></a>抖音底部导航栏</h2><h3 id="抖音样式的底部导航栏"><a href="#抖音样式的底部导航栏" class="headerlink" title="抖音样式的底部导航栏"></a>抖音样式的底部导航栏</h3><p>默认情况下底部导航栏的样子为：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gex1awy6ujj30hy02q3yx.jpg" alt="image.png"></p><p>我们要实现抖音的样子：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gex1b5z7ppj30k203emy3.jpg" alt="image.png"></p><p>实现思路有两个：</p><ol><li>可以完全自定义</li><li>在原来的基础上修改样式</li></ol><h3 id="实现基本样式"><a href="#实现基本样式" class="headerlink" title="实现基本样式"></a>实现基本样式</h3><p>可以通过配置实现基本的样式：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gex1dkn38oj30um0n6q6k.jpg" alt="image.png"></p><h3 id="实现中间的按钮"><a href="#实现中间的按钮" class="headerlink" title="实现中间的按钮"></a>实现中间的按钮</h3><p>实现思路：制作一个按钮，使用定位技术，定位到中间。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gex1szauohj30lb0rktb1.jpg" alt="image.png"></p><h3 id="按钮平均分布"><a href="#按钮平均分布" class="headerlink" title="按钮平均分布"></a>按钮平均分布</h3><p>因为底部有四个按钮，所以中间放一个+号按钮时，按钮不平均，<br>解决办法：底部导航栏 中再添加一个按钮，让它是五个按钮，这样就平均了</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gex1uac1zoj31pi17shdt.jpg" alt="image.png"></p><p>缺点：1. 底部导航栏中多出了一个没有用的按钮<br>\2. 点击+号旁边时有可能点击到底下的按钮</p><h3 id="实现录像功能"><a href="#实现录像功能" class="headerlink" title="实现录像功能"></a>实现录像功能</h3><p>点击 + 号时可以实现录像、拍照功能，这个功能可以通过<br><code>react-native-image-crop-picker</code> 包实现，这个包已经安装过了，直接使用即可。</p><ol><li>引入这个包</li></ol><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">import  ImagePicker  from  &#39;react-native-image-crop-picker&#39;;</span><br></pre></td></tr></table></figure><ol start="2"><li>为 + 号添加点击事件</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gex1v8kiu0j30fi09cmxr.jpg" alt="image.png"></p><p>整体代码</p><p>Index.js</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; View &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"><span class="keyword">import</span> &#123; createBottomTabNavigator &#125; <span class="keyword">from</span> <span class="string">'@react-navigation/bottom-tabs'</span>;</span><br><span class="line"><span class="keyword">import</span> ImagePicker <span class="keyword">from</span> <span class="string">'react-native-image-crop-picker'</span>;</span><br><span class="line"><span class="keyword">import</span> IconButton <span class="keyword">from</span> <span class="string">'../../components/button/IconButton'</span></span><br><span class="line"><span class="comment">// 创建底部导航器</span></span><br><span class="line"><span class="keyword">const</span> IndexBottomTabNavigator = createBottomTabNavigator();</span><br><span class="line"><span class="comment">// 导入四个页面</span></span><br><span class="line"><span class="keyword">import</span> IndexPage <span class="keyword">from</span> <span class="string">'./index/Index'</span></span><br><span class="line"><span class="keyword">import</span> CityPage <span class="keyword">from</span> <span class="string">'./city/Index'</span></span><br><span class="line"><span class="keyword">import</span> MessagePage <span class="keyword">from</span> <span class="string">'./message/Index'</span></span><br><span class="line"><span class="keyword">import</span> MePage <span class="keyword">from</span> <span class="string">'./me/Index'</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> Index = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;&gt;</span><br><span class="line">            &lt;IndexBottomTabNavigator.Navigator</span><br><span class="line">                tabBarOptions=&#123;&#123;</span><br><span class="line">                    showIcon: <span class="literal">false</span>, <span class="comment">// 无图标</span></span><br><span class="line">                    activeTintColor: <span class="string">'white'</span>, <span class="comment">// 选中时字体颜色</span></span><br><span class="line">                    labelStyle: &#123;</span><br><span class="line">                        <span class="comment">// 字体样式</span></span><br><span class="line">                        fontSize: <span class="number">18</span>,</span><br><span class="line">                        fontWeight: <span class="string">'bold'</span>,</span><br><span class="line">                    &#125;,</span><br><span class="line">                    style: &#123;</span><br><span class="line">                        backgroundColor: <span class="string">'black'</span>,</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;&#125;</span><br><span class="line">            &gt;</span><br><span class="line">                &lt;IndexBottomTabNavigator.Screen</span><br><span class="line">                    name=<span class="string">"Main"</span></span><br><span class="line">                    component=&#123;IndexPage&#125;</span><br><span class="line">                    options=&#123;&#123; <span class="attr">title</span>: <span class="string">'首页'</span> &#125;&#125;</span><br><span class="line">                /&gt;</span><br><span class="line">                &lt;IndexBottomTabNavigator.Screen</span><br><span class="line">                    name=<span class="string">"City"</span></span><br><span class="line">                    component=&#123;CityPage&#125;</span><br><span class="line">                    options=&#123;&#123; <span class="attr">title</span>: <span class="string">'城市'</span> &#125;&#125;</span><br><span class="line">                /&gt;</span><br><span class="line">                &lt;IndexBottomTabNavigator.Screen</span><br><span class="line">                    name=<span class="string">"Upload"</span></span><br><span class="line">                    component=&#123;CityPage&#125;</span><br><span class="line">                    options=&#123;&#123; <span class="attr">title</span>: <span class="string">'+'</span> &#125;&#125;</span><br><span class="line">                /&gt;</span><br><span class="line">                &lt;IndexBottomTabNavigator.Screen</span><br><span class="line">                    name=<span class="string">"Message"</span></span><br><span class="line">                    component=&#123;MessagePage&#125;</span><br><span class="line">                    options=&#123;&#123; <span class="attr">title</span>: <span class="string">'消息'</span> &#125;&#125;</span><br><span class="line">                /&gt;</span><br><span class="line">                &lt;IndexBottomTabNavigator.Screen</span><br><span class="line">                    name=<span class="string">"Me"</span></span><br><span class="line">                    component=&#123;MePage&#125;</span><br><span class="line">                    options=&#123;&#123; <span class="attr">title</span>: <span class="string">'我'</span> &#125;&#125;</span><br><span class="line">                /&gt;</span><br><span class="line">            &lt;<span class="regexp">/IndexBottomTabNavigator.Navigator&gt;</span></span><br><span class="line"><span class="regexp">            &lt;View style=&#123;&#123;</span></span><br><span class="line"><span class="regexp">                alignItems: 'center',</span></span><br><span class="line"><span class="regexp">            &#125;&#125;&gt;</span></span><br><span class="line"><span class="regexp">                &lt;View style=&#123;&#123;</span></span><br><span class="line"><span class="regexp">                    position: 'absolute',</span></span><br><span class="line"><span class="regexp">                    bottom: 0,</span></span><br><span class="line"><span class="regexp">                    backgroundColor: 'white',</span></span><br><span class="line"><span class="regexp">                    paddingLeft: 8,</span></span><br><span class="line"><span class="regexp">                    paddingRight: 8,</span></span><br><span class="line"><span class="regexp">                    borderRadius: 5,</span></span><br><span class="line"><span class="regexp">                    borderLeftWidth: 2,</span></span><br><span class="line"><span class="regexp">                    borderLeftColor: '#78E5E7',</span></span><br><span class="line"><span class="regexp">                    borderRightWidth: 2,</span></span><br><span class="line"><span class="regexp">                    borderRightColor: '#E54667',</span></span><br><span class="line"><span class="regexp">                &#125;&#125;&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;IconButton name="add" onPress=&#123;() =&gt; &#123;</span></span><br><span class="line"><span class="regexp">                        ImagePicker.openCamera(&#123;</span></span><br><span class="line"><span class="regexp">                            mediaType: 'video',</span></span><br><span class="line"><span class="regexp">                        &#125;)</span></span><br><span class="line"><span class="regexp">                            .then((img) =&gt; &#123;</span></span><br><span class="line"><span class="regexp">                                console.log(img);</span></span><br><span class="line"><span class="regexp">                            &#125;)</span></span><br><span class="line"><span class="regexp">                            .catch((v) =&gt; &#123;</span></span><br><span class="line"><span class="regexp">                                console.log(v);</span></span><br><span class="line"><span class="regexp">                            &#125;)</span></span><br><span class="line"><span class="regexp">                    &#125;&#125; /</span>&gt;</span><br><span class="line">                &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">            &lt;/</span>View&gt;</span><br><span class="line">        &lt;<span class="regexp">/&gt;</span></span><br><span class="line"><span class="regexp">    )</span></span><br><span class="line"><span class="regexp">&#125;</span></span><br><span class="line"><span class="regexp"></span></span><br><span class="line"><span class="regexp">export default Index</span></span><br></pre></td></tr></table></figure><br><h2 id="视频列表"><a href="#视频列表" class="headerlink" title="视频列表"></a>视频列表</h2><h3 id="上下滑动"><a href="#上下滑动" class="headerlink" title="上下滑动"></a>上下滑动</h3><p>实现原理：使用 RN 内置的 <code>FlatList</code> 组件可以实现视频上下滑动的视频列表。<br>这个组件几个重要的属性：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">data：要显示的数据，数组</span><br><span class="line">renderItem：函数，要显示的每条记录的内容</span><br><span class="line">keyExtractor：函数，为每条记录设置一个 key ，要求这个 key 必须是唯一的字符串</span><br><span class="line">pagingEnabled：布尔，是否一次滑动一页</span><br><span class="line">paused 属性，这个属性可以让视频停止播放。</span><br></pre></td></tr></table></figure><p>注意：要设置每条记录的高度。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1jcomc9ij311v0p7q7t.jpg" alt="image.png"></p><h3 id="左右滑动"><a href="#左右滑动" class="headerlink" title="左右滑动"></a>左右滑动</h3><p>实现左右滑动，官方有一个组件，但是已经废弃了，</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1jd7k211j319c0gyn66.jpg" alt="image.png"></p><p>官方推荐我们使用：<a href="https://github.com/react-native-community/react-native-viewpager" target="_blank" rel="noopener">https://github.com/react-native-community/react-native-viewpager</a></p><h4 id="安装"><a href="#安装" class="headerlink" title="安装"></a>安装</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">yarn add @react-native-community&#x2F;viewpager&#96;</span><br></pre></td></tr></table></figure><p>我们项目中已经在最开始安装好了。</p><h4 id="使用"><a href="#使用" class="headerlink" title="使用"></a>使用</h4><p>实现左右滑动：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kx1p5vcj31720zewy3.jpg" alt="image.png"></p><h4 id="通过点击按钮实现滑动"><a href="#通过点击按钮实现滑动" class="headerlink" title="通过点击按钮实现滑动"></a>通过点击按钮实现滑动</h4><p>ViewPager 组件中有一个 <code>setPage</code> 方法，调用这个方法可以实现页面的切换，<br>比如：要切换到第二个页面：<code>setPage(1)</code>。</p><p>知识点：使用 <code>ref</code> 来获取对一个组件的引用。</p><p>使用 ref 的步骤：</p><ol><li>先创建一个 ref：<code>React.createRef()</code></li><li>把创建的 ref 绑定到对应的组件上：<code>ref={创建的ref对象}</code></li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kxqfoctj31ne0zgx6p.jpg" alt="image.png"></p><h4 id="实现首页四个顶部按钮的布局"><a href="#实现首页四个顶部按钮的布局" class="headerlink" title="实现首页四个顶部按钮的布局"></a>实现首页四个顶部按钮的布局</h4><p>通过定位 和 flex 布局 技术可以实现页面的布局。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1ko9rwl6j31p0192b2a.jpg" alt="image.png"></p><h4 id="封装文字按钮"><a href="#封装文字按钮" class="headerlink" title="封装文字按钮"></a>封装文字按钮</h4><p>项目中有些按钮是一个文字，那么我们需要封装一个文字按钮组件。<br>文字要想能点击，需要使用 <code>TouchableWithoutFeedback</code> 组件套起来：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kpc7g3ij31200fs4cu.jpg" alt="image.png"></p><p>封装好之后，就可以这样使用了：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kslij3zj31o21467wi.jpg" alt="image.png"></p><h4 id="按钮下面的白色条"><a href="#按钮下面的白色条" class="headerlink" title="按钮下面的白色条"></a>按钮下面的白色条</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kthnvy7j30ji0bok0g.jpg" alt="image.png"></p><h5 id="先制作白线"><a href="#先制作白线" class="headerlink" title="先制作白线"></a>先制作白线</h5><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1ku5e83dj31pe1ayb2a.jpg" alt="image.png"></p><h5 id="制作白线的移动动画"><a href="#制作白线的移动动画" class="headerlink" title="制作白线的移动动画"></a>制作白线的移动动画</h5><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kusi9eij30ya1bwb29.jpg" alt="image.png"></p><h4 id="使用转换实现动画"><a href="#使用转换实现动画" class="headerlink" title="使用转换实现动画"></a>使用转换实现动画</h4><p>我们刚刚使用了 <code>left</code> 这个属性实现的动画，但是使用这个属性实现动画时，无法启用原生动画驱动功能 <code>useNativeDriver={false}</code>，性能不是特别好。<br>所以我们可以使用转换中的 translateX 来实现平移的动画，这个属性可以应用原生动画驱动，所以动画改写为：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kvec0o9j312813aqop.jpg" alt="image.png"></p><p>总结：实现动画时，尽量使用转换 (transform) 中的属性，因为这些属性可以启用 RN 的原生动画驱动以提高性能。</p><h4 id="在左右滑动时，白线也移动"><a href="#在左右滑动时，白线也移动" class="headerlink" title="在左右滑动时，白线也移动"></a>在左右滑动时，白线也移动</h4><p>现在只有点击两个按钮时白线才会移动，我们应该让左右滑动屏幕时白线也随着一起移动。<br>ViewPager 这个组件上有一个事件 <code>onPageSelected</code> ，这个事件会在每次滑动完成之后调用，所以我们就可以在每次滑动完之后获取当前的下标，然后让白线移动。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kw7uhb6j30xe0piapn.jpg" alt="image.png"></p><p>加了代码之后在滑动时白线也会随之移动。</p><h4 id="不同屏幕尺寸适配"><a href="#不同屏幕尺寸适配" class="headerlink" title="不同屏幕尺寸适配"></a>不同屏幕尺寸适配</h4><p>布局时要注意，有些写死的坐标位置 ，在不同的屏幕尺寸上位置会不同。所以布局时尽量不要写死一定数字：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kzej0phj31r00c21kx.jpg" alt="image.png"></p><p>解决办法：</p><p>用一个 View 套起来，然后布局：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf1kzv0geij311c0vckjl.jpg" alt="image.png"></p><p>代码：</p><figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> React <span class="keyword">from</span> <span class="string">'react'</span></span><br><span class="line"><span class="keyword">import</span> &#123; StyleSheet, View, Animated &#125; <span class="keyword">from</span> <span class="string">'react-native'</span></span><br><span class="line"><span class="comment">// 引入组件</span></span><br><span class="line"><span class="keyword">import</span> VideoList <span class="keyword">from</span> <span class="string">'../../../components/video/VideoList'</span></span><br><span class="line"><span class="keyword">import</span> ViewPager <span class="keyword">from</span> <span class="string">'@react-native-community/viewpager'</span></span><br><span class="line"><span class="keyword">import</span> IconButton <span class="keyword">from</span> <span class="string">'../../../components/button/IconButton'</span>;</span><br><span class="line"><span class="keyword">import</span> TextButton <span class="keyword">from</span> <span class="string">'../../../components/button/TextButton'</span>;</span><br><span class="line"><span class="comment">// 创建一个 ref</span></span><br><span class="line"><span class="keyword">const</span> viewPageRef = React.createRef();</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> Video = <span class="function"><span class="params">()</span> =&gt;</span> &#123;</span><br><span class="line">    <span class="comment">// 白线左边的位置</span></span><br><span class="line">    <span class="keyword">const</span> [lineLeft, setLineLeft] = React.useState(<span class="keyword">new</span> Animated.Value(<span class="number">0</span>))</span><br><span class="line">    <span class="keyword">return</span> (</span><br><span class="line">        &lt;&gt;</span><br><span class="line">            &#123;<span class="comment">/* initialPage: 最开始使用哪个页面 */</span>&#125;</span><br><span class="line">            &lt;ViewPager</span><br><span class="line">                onPageSelected=&#123;(e) =&gt; &#123;</span><br><span class="line">                    <span class="keyword">let</span> toValue = e.nativeEvent.position === <span class="number">0</span> ? <span class="number">0</span> : <span class="number">51</span>;</span><br><span class="line">                    Animated.timing(lineLeft, &#123;</span><br><span class="line">                        toValue,</span><br><span class="line">                        duration: <span class="number">200</span>, <span class="comment">// 0.2s</span></span><br><span class="line">                        useNativeDriver: <span class="literal">true</span>, <span class="comment">// 是否启用原生动画驱动（left动画不支持原生）</span></span><br><span class="line">                    &#125;).start();</span><br><span class="line">                &#125;&#125;</span><br><span class="line">                ref=&#123;viewPageRef&#125;</span><br><span class="line">                style=&#123;styles.container&#125;</span><br><span class="line">                initialPage=&#123;<span class="number">0</span>&#125;</span><br><span class="line">            &gt;</span><br><span class="line">                &#123;<span class="comment">/* 关注 */</span>&#125;</span><br><span class="line">                &lt;View key=<span class="string">"gz"</span>&gt;</span><br><span class="line">                    &lt;VideoList /&gt;</span><br><span class="line">                &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">                &#123;/</span>* 推荐 *<span class="regexp">/&#125;</span></span><br><span class="line"><span class="regexp">                &lt;View key="tj"&gt;</span></span><br><span class="line"><span class="regexp">                    &lt;VideoList /</span>&gt;</span><br><span class="line">                &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">            &lt;/</span>ViewPager&gt;</span><br><span class="line">            &#123;<span class="comment">/* 按钮列表 */</span>&#125;</span><br><span class="line">            &lt;View style=&#123;styles.btnList&#125;&gt;</span><br><span class="line">                &lt;IconButton name=<span class="string">"live-tv"</span> color=<span class="string">"white"</span> /&gt;</span><br><span class="line">                &lt;View style=&#123;styles.textBtnList&#125;&gt;</span><br><span class="line">                    &lt;View</span><br><span class="line">                        style=&#123;&#123;</span><br><span class="line">                            <span class="comment">// backgroundColor: 'red',</span></span><br><span class="line">                            flexDirection: <span class="string">'row'</span>,</span><br><span class="line">                            paddingLeft: <span class="number">0</span>,</span><br><span class="line">                        &#125;&#125;&gt;</span><br><span class="line">                        &lt;TextButton</span><br><span class="line">                            style=&#123;[styles.textBtnLabel,</span><br><span class="line">                            &#123;</span><br><span class="line">                                paddingRight: <span class="string">'5%'</span>,</span><br><span class="line">                            &#125;,]&#125;</span><br><span class="line">                            title=<span class="string">"关注"</span></span><br><span class="line">                            onPress=&#123;() =&gt; &#123;</span><br><span class="line">                                <span class="comment">// 切换屏幕内容</span></span><br><span class="line">                                viewPageRef.current.setPage(<span class="number">0</span>)</span><br><span class="line">                                <span class="comment">// 白线移动的动画</span></span><br><span class="line">                                Animated.timing(lineLeft, &#123;</span><br><span class="line">                                    toValue: <span class="number">0</span>,</span><br><span class="line">                                    duration: <span class="number">200</span>, <span class="comment">// 0.2s</span></span><br><span class="line">                                    useNativeDriver: <span class="literal">true</span>, <span class="comment">// 是否启用原生动画驱动（left动画不支持原生）</span></span><br><span class="line">                                &#125;).start();</span><br><span class="line">                            &#125;&#125; /&gt;</span><br><span class="line">                        &lt;TextButton</span><br><span class="line">                            style=&#123;styles.textBtnLabel&#125;</span><br><span class="line">                            title=<span class="string">"推荐"</span></span><br><span class="line">                            onPress=&#123;() =&gt; &#123;</span><br><span class="line">                                <span class="comment">// 切换屏幕内容</span></span><br><span class="line">                                viewPageRef.current.setPage(<span class="number">1</span>)</span><br><span class="line">                                <span class="comment">// 白线移动的动画</span></span><br><span class="line">                                Animated.timing(lineLeft, &#123;</span><br><span class="line">                                    toValue: <span class="number">51</span>,</span><br><span class="line">                                    duration: <span class="number">200</span>, <span class="comment">// 0.2s</span></span><br><span class="line">                                    useNativeDriver: <span class="literal">true</span>, <span class="comment">// 是否启用原生动画驱动（left动画不支持原生）</span></span><br><span class="line">                                &#125;).start();</span><br><span class="line">                            &#125;&#125; /&gt;</span><br><span class="line">                        &lt;Animated.View style=&#123;[styles.line, &#123;</span><br><span class="line">                            transform: [&#123;</span><br><span class="line">                                translateX: lineLeft</span><br><span class="line">                            &#125;]</span><br><span class="line">                        &#125;]&#125; /&gt;</span><br><span class="line">                    &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">                &lt;/</span>View&gt;</span><br><span class="line">                &lt;IconButton name=<span class="string">"search"</span> color=<span class="string">"white"</span> /&gt;</span><br><span class="line">            &lt;<span class="regexp">/View&gt;</span></span><br><span class="line"><span class="regexp">        &lt;/</span>&gt;</span><br><span class="line">    )</span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line"><span class="keyword">export</span> <span class="keyword">default</span> Video</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> styles = StyleSheet.create(&#123;</span><br><span class="line">    container: &#123;</span><br><span class="line">        flex: <span class="number">1</span>,</span><br><span class="line">    &#125;,</span><br><span class="line">    btnList: &#123;</span><br><span class="line">        paddingLeft: <span class="number">10</span>,</span><br><span class="line">        paddingRight: <span class="number">10</span>,</span><br><span class="line">        position: <span class="string">'absolute'</span>,</span><br><span class="line">        top: <span class="number">30</span>,</span><br><span class="line">        flexDirection: <span class="string">'row'</span>, <span class="comment">// 子元素横着</span></span><br><span class="line">    &#125;,</span><br><span class="line">    textBtnList: &#123;</span><br><span class="line">        flex: <span class="number">1</span>, <span class="comment">// 沾满所有可用空间</span></span><br><span class="line">        flexDirection: <span class="string">'row'</span>, <span class="comment">// 子元素横向排列</span></span><br><span class="line">        alignItems: <span class="string">'center'</span>,</span><br><span class="line">        justifyContent: <span class="string">'center'</span>,</span><br><span class="line">    &#125;,</span><br><span class="line">    textBtnLabel: &#123;</span><br><span class="line">        color: <span class="string">'white'</span>,</span><br><span class="line">        fontSize: <span class="number">18</span>,</span><br><span class="line">        fontWeight: <span class="string">'bold'</span>,</span><br><span class="line">    &#125;,</span><br><span class="line">    line: &#123;</span><br><span class="line">        backgroundColor: <span class="string">'white'</span>,</span><br><span class="line">        height: <span class="number">5</span>,</span><br><span class="line">        width: <span class="number">35</span>,</span><br><span class="line">        position: <span class="string">'absolute'</span>,</span><br><span class="line">        bottom: <span class="number">-5</span>,</span><br><span class="line">        left: <span class="number">0</span>,</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure><h2 id="解决首页评论嵌套-FlatList-组件的问题"><a href="#解决首页评论嵌套-FlatList-组件的问题" class="headerlink" title="解决首页评论嵌套 FlatList 组件的问题"></a>解决首页评论嵌套 FlatList 组件的问题</h2><p>在 RN 中如果一个 FlatList 组件中嵌套了另一个 FlatList 会导致内部的 FlatList 无法滚动加载，比如首页的评论就无法滚动：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2nh2xsrij30qq11se81.jpg" alt="image.png"></p><p>嵌套 使用导航失效：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ninkty6j31js0uqe81.jpg" alt="image.png"></p><p>解决思路：把内层的 FlatList 拿出来放到首页的最外层组件中写。<br>在首页最外层（pages/main/Video.js) 中添加一个评论的框，把评论放到这里就互不影响了，都可以滚动了</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2o4gsw8yj31i80us1kx.jpg" alt="image.png"></p><p>问题：原来每个视频中自带一个评论列表，显示自己的评论，而现在这样改完之后，所有视频就要共用同一个评论列表，这就要注意评论数据传递的问题了，每当切换视频时，同时要切换评论框中的评论数据。</p><h3 id="先封装评论条目组件"><a href="#先封装评论条目组件" class="headerlink" title="先封装评论条目组件"></a>先封装评论条目组件</h3><p>把原来每个评论的组件单独写到一个文件中：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ocye9u5j319i13ib29.jpg" alt="image.png"></p><h3 id="在首页评论框中使用-FlatList-组件来制作评论条目的列表"><a href="#在首页评论框中使用-FlatList-组件来制作评论条目的列表" class="headerlink" title="在首页评论框中使用 FlatList 组件来制作评论条目的列表"></a>在首页评论框中使用 FlatList 组件来制作评论条目的列表</h3><ol><li>先引入组件</li></ol><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">import  CommentItem  from  &#39;..&#x2F;..&#x2F;..&#x2F;components&#x2F;comment&#x2F;CommentItem&#39;;</span><br></pre></td></tr></table></figure><ol start="2"><li>制作列表</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2odnbzw2j30uo0a6jx7.jpg" alt="image.png"></p><p>效果：评论列表拿到首页</p><p><img src="https://img.kancloud.cn/63/f3/63f3031567b83c6040eb8337a254d4ba_672x1202.png" alt="img"></p><h3 id="把外层这个评论框单独制作成一个组件"><a href="#把外层这个评论框单独制作成一个组件" class="headerlink" title="把外层这个评论框单独制作成一个组件"></a>把外层这个评论框单独制作成一个组件</h3><p>我们应该把外层灰色的框制作成一个独立的可以打开、关闭的组件，然后以后可以直接使用，使用时里面可以放任何内容。</p><h4 id="封装-Panel-组件"><a href="#封装-Panel-组件" class="headerlink" title="封装 Panel 组件"></a>封装 Panel 组件</h4><p>通过 children 属性可以获取子组件的内容：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2pyd2ng6j324o0kenpd.jpg" alt="image.png"></p><h4 id="添加动画"><a href="#添加动画" class="headerlink" title="添加动画"></a>添加动画</h4><p>为框添加一个关闭按钮并实现点击时的关闭动画</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2pz6x1oxj30mu1a2tsl.jpg" alt="image.png"></p><h3 id="控制组件的打开"><a href="#控制组件的打开" class="headerlink" title="控制组件的打开"></a>控制组件的打开</h3><p>现在我们需要其他组件（可能是父组件、也可能是兄弟组件，也可能是完全不在一个级别的组件）来控制这个组件的打开功能。</p><ol><li>定义一个用来打开这个面板的方法</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2pzo7rumj31480uunj2.jpg" alt="image.png"></p><ol start="2"><li>通过一个属性来控制是否调用这个函数</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q066a65j30tu0vuh8d.jpg" alt="image.png"></p><p>现在其他组件就可以通过这个组件的 open 属性来控制是否打开了。</p><h4 id="添加一个-onClose-事件（双向绑定）"><a href="#添加一个-onClose-事件（双向绑定）" class="headerlink" title="添加一个 onClose 事件（双向绑定）"></a>添加一个 onClose 事件（双向绑定）</h4><p>每当组件中关闭了面板时要通知父组件。</p><p><img src="https://img.kancloud.cn/0e/22/0e22ef53f76e0e2f2cecea4619f170a2_1192x1718.png" alt="img"></p><p>到此有了 open 和 onClose 两个属性之后就实现了打开关闭功能的双向绑定，基本就可以使用了。</p><h4 id="跨层级使用这个-Panel-组件"><a href="#跨层级使用这个-Panel-组件" class="headerlink" title="跨层级使用这个 Panel 组件"></a>跨层级使用这个 Panel 组件</h4><p>难点：不同层级组件共享操作。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q15jmxlj31bs1287wh.jpg" alt="image.png"></p><ol><li>在 Video.js （父组件中）定义属性并绑定到 评论上</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q1uqqshj315q0y04ge.jpg" alt="image.png"></p><ol start="2"><li><p>使用 Context 共享这个数据<br>2.1 创建 Context</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q2ki4m8j30xs0d4jzu.jpg" alt="image.png"></p><p>2.2 使用 Context 共享数据</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q2s04z8j317s0w61kx.jpg" alt="image.png"></p><p>2.3 在子组件的评论按钮上调用这个共享的方法<br>在 VideoPlay 组件中引入并使用</p></li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q3sq572j311o19m4qp.jpg" alt="image.png"></p><p>最后可以把 VideoPlay 中原来的打开评论的代码都删除，最终删除完之后：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2q48zdekj30x21ackgg.jpg" alt="image.png"></p><br><h1 id="同城页面"><a href="#同城页面" class="headerlink" title="同城页面"></a>同城页面</h1><h2 id="创建栈导航器管理两个页面"><a href="#创建栈导航器管理两个页面" class="headerlink" title="创建栈导航器管理两个页面"></a>创建栈导航器管理两个页面</h2><p>因为同城这个页面中是由两个页面组成的：“列表”和“详情”，这两个页面应该使用栈导航器组织起来。</p><p>为了让这两个页面可以互相跳转，我们需要使用一个导航器管理两个页面，根据两个页面跳转的特点：从列表跳到详情，在详情页还能返回，这种可以返回的跳转基本就是 <code>Stack（栈）</code> 导航器。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2rgd7r16j31xi11qkjl.jpg" alt="image.png"></p><p>总结：如果一个页面要跳转到另一个页面，那么这些可以互相跳转的页面必须要使用导航器管理起来！</p><br><h2 id="制作城市列表页"><a href="#制作城市列表页" class="headerlink" title="制作城市列表页"></a>制作城市列表页</h2><h3 id="配置标题栏"><a href="#配置标题栏" class="headerlink" title="配置标题栏"></a>配置标题栏</h3><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ruza1r4j31mi12cb29.jpg" alt="image.png"></p><h3 id="列表页的状态栏"><a href="#列表页的状态栏" class="headerlink" title="列表页的状态栏"></a>列表页的状态栏</h3><p>可以使用 RN 中内置的一个组件 <code>StatusBar</code> 设置状态栏的背景色、字体颜色、是否透明等：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2rxmway3j31l80lck9c.jpg" alt="image.png"></p><h3 id="动态设置标题栏"><a href="#动态设置标题栏" class="headerlink" title="动态设置标题栏"></a>动态设置标题栏</h3><p>页面的标题栏可以通过调用 <code>navigation.setOptions</code> 方法来动态的设置。<br>所以页面上的地区应该：</p><ol><li>当用户打开这个页面时，根据用户的 IP 地址获取这个用户所在的城市</li><li>通过调用 <code>navigation.setOptions</code> 方法把城市设置成为标题</li></ol><p>为了演示，我们先不获取地区，先随机设置一个，比如：全州。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2rywv67yj31k20xmu0j.jpg" alt="image.png"></p><p>扩展：获取用户详细地址。</p><h3 id="视频列表-1"><a href="#视频列表-1" class="headerlink" title="视频列表"></a>视频列表</h3><p>在 RN 中制作列表使用 <code>FlatList</code> 组件实现。<br>在 RN 中实现滚动需要使用组件：</p><ol><li>ScrollView 组件：数据少时，比如只需要滚动几件时使用。</li><li>FlatList 组件：长数据列表时，性能更好。</li><li>SectionList 组件：</li></ol><p>ScrollView 和 FlatList 组件的区别：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2rzlmol0j319q0g0n7p.jpg" alt="image.png"></p><h4 id="背景图片"><a href="#背景图片" class="headerlink" title="背景图片"></a>背景图片</h4><p>在 RN 中背景图片必须要使用 <code>ImageBackground</code> 组件来实现。（这和网页中使用 CSS 的 backgroundImage 不同<del>~</del>）</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2se1ct0qj31hy0mk1iy.jpg" alt="image.png"></p><h4 id="两列数据"><a href="#两列数据" class="headerlink" title="两列数据"></a>两列数据</h4><p>FlatList 组件中有一个属性：<code>numColumns</code> 可以设置列数据。<br>注意：每条记录上要使用 flex 布局，否则无效。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2segttp2j31i213m4qp.jpg" alt="image.png"></p><h4 id="下拉刷新"><a href="#下拉刷新" class="headerlink" title="下拉刷新"></a>下拉刷新</h4><p><code>FlatList</code> 组件中有两个属性实现下拉刷新功能的：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">refreshing：布尔，是否显示加载的图标。</span><br><span class="line">onRefresh：函数，当下拉时会触发函数。</span><br></pre></td></tr></table></figure><h4 id="显示刷新图标"><a href="#显示刷新图标" class="headerlink" title="显示刷新图标"></a>显示刷新图标</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2seq7csej31e012ynpd.jpg" alt="image.png"></p><h4 id="加载数据并隐藏图标"><a href="#加载数据并隐藏图标" class="headerlink" title="加载数据并隐藏图标"></a>加载数据并隐藏图标</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sez7qwaj31bs14qkjl.jpg" alt="image.png"></p><h4 id="触底加载更多"><a href="#触底加载更多" class="headerlink" title="触底加载更多"></a>触底加载更多</h4><p><code>FlatList</code> 组件中有以下几个属性可以用来实现触底加载更多：</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">ListFooterComponent：组件，列表最底部显示的加载图标。</span><br><span class="line">onEndReachedThreshold：数值，距离底部的百分比，比如：0.2，含义当滚动到距离底部20%的时候触发加载更多</span><br><span class="line">onEndReached：函数，当滚动到底部时触发的函数。</span><br></pre></td></tr></table></figure><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sfh3ibsj31ok0v8b29.jpg" alt="image.png"></p><h3 id="控制触底加载的频率"><a href="#控制触底加载的频率" class="headerlink" title="控制触底加载的频率"></a>控制触底加载的频率</h3><p>如果用户在底部上下来回滑动，会导致频繁的触发触底函数，所以我们应该通过一个变量控制一下，如果当前正在加载中，那么即使再次触发也不要触发加载事件。</p><ol><li>定义一个普通的全局变量<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sfolcn8j31040nkwuu.jpg" alt="image.png"></li><li>在函数中通过这个变量来控制一次只触发一次</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sg0ccc5j30wi0nwneg.jpg" alt="image.png"></p><p>问题：定义一个普通变量，和定义一个 state 数据有什么区别？<br>普通变量：在修改时，不会触发页面重新渲染。<br>state 数据：在修改之后，会触发组件的重新渲染。</p><p>总结：对页面内容没有任何影响 的数据可以定义为普通变量，对页面有影响 的数据，比如：是否显示加载图标的state数据，会影响 到页面中是否显示图片，这种需要定义为state。</p><br><h2 id="详情页"><a href="#详情页" class="headerlink" title="详情页"></a>详情页</h2><h3 id="列表中点击跳转"><a href="#列表中点击跳转" class="headerlink" title="列表中点击跳转"></a>列表中点击跳转</h3><p>在 RN 中默认只有 <code>Button</code> 组件才能点击。<br>为了让其他组件都能够被点击，我们需要使用 RN 中提供的一套以 <code>Touchable</code> 开头的组件做为父组件：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sh0xfk6j30do078dgt.jpg" alt="image.png"></p><p>所以只要用其中一个把要点击的组件套起来即可：</p><p>City.js</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sihr2mwj315210ie81.jpg" alt="image.png"></p><h3 id="详情页-1"><a href="#详情页-1" class="headerlink" title="详情页"></a>详情页</h3><h4 id="引入全屏播放的组件"><a href="#引入全屏播放的组件" class="headerlink" title="引入全屏播放的组件"></a>引入全屏播放的组件</h4><p>我们之前已经写好了一个组件，可以全屏播放视频：<code>VideoPlayer</code> 。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sjik27dj31so11kqv5.jpg" alt="image.png"></p><h4 id="让标题栏和状态栏透明"><a href="#让标题栏和状态栏透明" class="headerlink" title="让标题栏和状态栏透明"></a>让标题栏和状态栏透明</h4><p>通过配置可以实现：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sks30gkj31ws114npe.jpg" alt="image.png"></p><h2 id="自定义标题栏左右按钮图标"><a href="#自定义标题栏左右按钮图标" class="headerlink" title="自定义标题栏左右按钮图标"></a>自定义标题栏左右按钮图标</h2><ol><li>先引入图标组件<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2skhxf36j312y0bsthh.jpg" alt="image.png"></li><li>使用图标做为左上角图片</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2sk9uw66j31o40kme81.jpg" alt="image.png"></p><br><h1 id="我的页面"><a href="#我的页面" class="headerlink" title="我的页面"></a>我的页面</h1><h2 id="我的子页面导航器"><a href="#我的子页面导航器" class="headerlink" title="我的子页面导航器"></a>我的子页面导航器</h2><p>在我的这个页面，还有一些子页面，比如：编辑资料、订单等等。<br>并且这些页面都属于栈导航器，所以需要为这些页面创建栈导航器来管理。</p><h3 id="创建子页面"><a href="#创建子页面" class="headerlink" title="创建子页面"></a>创建子页面</h3><p>有很多子页面，我们先创建这三个：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2tx0p90pj30jo0aetbe.jpg" alt="image.png"></p><h3 id="创建导航器-1"><a href="#创建导航器-1" class="headerlink" title="创建导航器"></a>创建导航器</h3><p>页面必须先由导航器管理起来之后才能使用。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2twicp2kj314w16i1kx.jpg" alt="image.png"></p><p>现在我们先写三个子页面，如果有更多的子页面需要都引入注册到导航器中。</p><h3 id="我的个人中心布局"><a href="#我的个人中心布局" class="headerlink" title="我的个人中心布局"></a>我的个人中心布局</h3><h4 id="我的页面标题栏配置"><a href="#我的页面标题栏配置" class="headerlink" title="我的页面标题栏配置"></a>我的页面标题栏配置</h4><p>默认是有标题栏 的，但我们希望把它隐藏起来。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2tw9o612j31680wyqtm.jpg" alt="image.png"></p><h4 id="顶部背景图"><a href="#顶部背景图" class="headerlink" title="顶部背景图"></a>顶部背景图</h4><p>在 RN 中制作背景图要使用 <code>ImageBackground</code> 组件，并且要设置宽、高，否则图片显示不出来。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2tw2753yj31rs128npd.jpg" alt="image.png"></p><h4 id="我的头像部分的布局"><a href="#我的头像部分的布局" class="headerlink" title="我的头像部分的布局"></a>我的头像部分的布局</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2tvske1kj31fw15cnpd.jpg" alt="image.png"></p><br><h2 id="右侧抽屉导航"><a href="#右侧抽屉导航" class="headerlink" title="右侧抽屉导航"></a>右侧抽屉导航</h2><h3 id="创建-Drawer-组件并实现动画"><a href="#创建-Drawer-组件并实现动画" class="headerlink" title="创建 Drawer 组件并实现动画"></a>创建 Drawer 组件并实现动画</h3><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u26iixoj31e61ccx6p.jpg" alt="image.png"></p><p>样式：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u2ntk6ij30hu0yo14o.jpg" alt="image.png"></p><p>现在这个功能存在的问题：</p><ol><li>不能左右滑动：官方提供的 <code>PanResponder</code> 组件可以实现手势滑动功能。</li><li>APP 总体向左平移</li><li>无法把底部导航给盖（因为是子页面，所以要解决这个问题，需要在最外层实现这个功能）</li></ol><h3 id="导航栏上收缩的二级导航"><a href="#导航栏上收缩的二级导航" class="headerlink" title="导航栏上收缩的二级导航"></a>导航栏上收缩的二级导航</h3><h4 id="静态布局"><a href="#静态布局" class="headerlink" title="静态布局"></a>静态布局</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u8x5z2mj31by19ib29.jpg" alt="image.png"></p><h4 id="制作折叠动画"><a href="#制作折叠动画" class="headerlink" title="制作折叠动画"></a>制作折叠动画</h4><h5 id="制作三角形"><a href="#制作三角形" class="headerlink" title="制作三角形"></a>制作三角形</h5><p>直接使用 CSS 来制作一个三角形。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u8nzupgj31jm14sb29.jpg" alt="image.png"></p><h5 id="添加旋转动画"><a href="#添加旋转动画" class="headerlink" title="添加旋转动画"></a>添加旋转动画</h5><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u8awx48j31pi1bsx6p.jpg" alt="image.png"></p><p>点击之后可以旋转，但是存在两个问题：</p><ol><li>只能点击一次，只能旋转一次</li><li>旋转的轴心不是中心点</li></ol><p>问题一、解决：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u82yo0lj31ne0ymb29.jpg" alt="image.png"></p><p>问题二、解决<br>因为旋转时是旋转的父元素，父元素以中心点旋转，所以只要让三角形在父元素的正中心即可。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u7tbgkoj30wa0fi7bg.jpg" alt="image.png"></p><h5 id="订单按钮和三角色形按钮定位"><a href="#订单按钮和三角色形按钮定位" class="headerlink" title="订单按钮和三角色形按钮定位"></a>订单按钮和三角色形按钮定位</h5><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u7kn5ooj31a81aihdt.jpg" alt="image.png"></p><h5 id="制作二级按钮"><a href="#制作二级按钮" class="headerlink" title="制作二级按钮"></a>制作二级按钮</h5><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u7cfxc9j31n4104hdt.jpg" alt="image.png"></p><p>添加样式：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u73kes5j30b2078wgx.jpg" alt="image.png"></p><h5 id="实现折叠动画"><a href="#实现折叠动画" class="headerlink" title="实现折叠动画"></a>实现折叠动画</h5><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u6v1i3fj31m0182qv5.jpg" alt="image.png"></p><h3 id="扩展：跳转对象"><a href="#扩展：跳转对象" class="headerlink" title="扩展：跳转对象"></a>扩展：跳转对象</h3><p>如果在一级页面中要实现跳转，可以直接使用 <code>navigation</code> 对象。<br>如果不是一级页面，比如在一级页面中引入了 a组件，a组件又引入了 b 组件，然后在 b 组件中要实现跳转，这时可以：<br>方法一.、在一级页面中把 navigation 传给 a 组件，a组件再传给 b 组件，然后 b 组件中就可以跳转了。（层级深时比较麻烦）<br>方法二、有一个 <code>useNavigation</code> 的 Hook 函数，可以直接获取到导航对象</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line">&#x2F;&#x2F; 1. 引入</span><br><span class="line">import  &#123; useNavigation &#125;  from  &#39;@react-navigation&#x2F;native&#39;;</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F;...</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 2. 生成对象</span><br><span class="line">const navigation &#x3D;  useNavigation();</span><br><span class="line"></span><br><span class="line">&#x2F;&#x2F; 3. 使用</span><br><span class="line">navigation.navigate(&#39;页面&#39;)</span><br></pre></td></tr></table></figure><p>示例：在 Menu 组件中实现跳转</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2u6dz30bj314q1941kx.jpg" alt="image.png"></p><br><h2 id="tab-导航-和-三列的列表"><a href="#tab-导航-和-三列的列表" class="headerlink" title="tab 导航 和 三列的列表"></a>tab 导航 和 三列的列表</h2><h3 id="需要使用到的组件"><a href="#需要使用到的组件" class="headerlink" title="需要使用到的组件"></a>需要使用到的组件</h3><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uc8eg95j30y40oe7wh.jpg" alt="image.png"></p><h3 id="三列左右-滑动"><a href="#三列左右-滑动" class="headerlink" title="三列左右 滑动"></a>三列左右 滑动</h3><h4 id="基本功能"><a href="#基本功能" class="headerlink" title="基本功能"></a>基本功能</h4><p>需要使用 <code>ViewPager</code> 组件实现。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ucqtevcj31ci15ghdt.jpg" alt="image.png"></p><h4 id="放三个按钮"><a href="#放三个按钮" class="headerlink" title="放三个按钮"></a>放三个按钮</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uk63iv9j31gc0h8trn.jpg" alt="image.png"></p><p>三个按钮样式：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ujx4b21j30ew09wadj.jpg" alt="image.png"></p><h4 id="点击三个按钮时滑动框"><a href="#点击三个按钮时滑动框" class="headerlink" title="点击三个按钮时滑动框"></a>点击三个按钮时滑动框</h4><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ujq1kfmj31ek180npd.jpg" alt="image.png"></p><h4 id="选中按钮的样式"><a href="#选中按钮的样式" class="headerlink" title="选中按钮的样式"></a>选中按钮的样式</h4><ol><li>先定义一个选中时的样式<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ujfde05j30sk0dadle.jpg" alt="image.png"></li><li>定义一个变量，通过这个变量保存当前被选中的框的下标<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uj6awpkj315u162x2b.jpg" alt="image.png"></li><li>根据这个变量来判断在哪个按钮上添加选中的样式</li></ol><h4 id="滑动框时同步更新按钮状态"><a href="#滑动框时同步更新按钮状态" class="headerlink" title="滑动框时同步更新按钮状态"></a>滑动框时同步更新按钮状态</h4><p>当滑动切换时，按钮也应该同步切换。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ui7vkukj30sa0huwmb.jpg" alt="image.png"></p><h4 id="黄线跟着滑动"><a href="#黄线跟着滑动" class="headerlink" title="黄线跟着滑动"></a>黄线跟着滑动</h4><h5 id="画一个黄线"><a href="#画一个黄线" class="headerlink" title="画一个黄线"></a>画一个黄线</h5><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uhxhpyyj31go0fqh0k.jpg" alt="image.png"></p><h5 id="制作动画"><a href="#制作动画" class="headerlink" title="制作动画"></a>制作动画</h5><p>动画原理修改 left 的值，这个值有三种情况：<br>left: ‘0%’ ：最左边<br>left: ‘33.333333%’ ：中间<br>left: ‘66.666666%’ : 右边</p><ol><li>定义一个变量，用来黄线的位置<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uhmmob6j316q0jcaqx.jpg" alt="image.png"></li><li>把这个变量绑定到组件的 left 上<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uhe4yp0j30te0j4ws6.jpg" alt="image.png"></li><li>每当当前选中的下标发生改变时执行动画，所以需要添加一个类似监听器的功能监听当前下标，当下标改变时，就滚动到这个下标</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2uh42otwj318g0qse3a.jpg" alt="image.png"></p><h3 id="使用-FlatList-实现三列的列表"><a href="#使用-FlatList-实现三列的列表" class="headerlink" title="使用 FlatList 实现三列的列表"></a>使用 FlatList 实现三列的列表</h3><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2ugpc5l0j318q0qs7wf.jpg" alt="image.png"></p><p>到此我的页面就写完了，但是抽屉导航还是有问题。</p><h2 id="抽屉导航问题"><a href="#抽屉导航问题" class="headerlink" title="抽屉导航问题"></a>抽屉导航问题</h2><p>在 “我的” 页面中可以打开抽屉导航。</p><h3 id="盖住APP"><a href="#盖住APP" class="headerlink" title="盖住APP"></a>盖住APP</h3><p>为了让抽屉导航能够把整个 APP（包含底部导航）都盖上，那么这个抽屉导航的代码，需要写在最外层组件中：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w51xt34j321s15cnpe.jpg" alt="image.png"></p><h3 id="整个-APP-整体向左滑动"><a href="#整个-APP-整体向左滑动" class="headerlink" title="整个 APP 整体向左滑动"></a>整个 APP 整体向左滑动</h3><p>为了让整个 APP 整体向左滑动，所以代码需要写在 “最外层” 组件中，控制整个 APP。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w4tomlkj321o14ke82.jpg" alt="image.png"></p><p>说明：向左移动可以使用 left 也可以使用 transform 实现，因为这个功能需要做成一个动画，而 transform 可以使用原生驱动动画，所以性能更好，所以这里选择使用 transform。</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w4m8faej31g015ce82.jpg" alt="image.png"></p><h3 id="扩展知识点：布局时的层级"><a href="#扩展知识点：布局时的层级" class="headerlink" title="扩展知识点：布局时的层级"></a>扩展知识点：布局时的层级</h3><p>在 RN 中默认写在后面的组件会盖在前面的组件上，所以调整一个组件的层级：</p><ol><li>把高层级组件写在后面</li><li>通过 <code>zIndex</code> 来设置层级</li></ol><h3 id="透明层"><a href="#透明层" class="headerlink" title="透明层"></a>透明层</h3><p>主 APP 上要有一个层盖上，当点击这个层时还能滑动 APP 回原位置：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w4bt4vpj325k1064qq.jpg" alt="image.png"></p><h3 id="控制透明层的显示和隐藏"><a href="#控制透明层的显示和隐藏" class="headerlink" title="控制透明层的显示和隐藏"></a>控制透明层的显示和隐藏</h3><ol><li>定义变量<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w43ufmhj310g0c2dnn.jpg" alt="image.png"></li><li>通过这个变量判断组件是否显示（条件渲染）<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w3v88jwj30ts0wunf4.jpg" alt="image.png"></li><li>在显示和隐藏抽屉时修改变量的值</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w3nsd3qj30qm0eqahg.jpg" alt="image.png"></p><h3 id="在子组件中控制这个抽屉动画"><a href="#在子组件中控制这个抽屉动画" class="headerlink" title="在子组件中控制这个抽屉动画"></a>在子组件中控制这个抽屉动画</h3><p>难点：抽屉的动画代码是写在最外层的父组件中的，如何在子组件“我的”这个页面中来调用？<br>解决办法：方法很多，其中一个思路是：数据在组件中的传递。<br>我们只要能把动画的代码传递到子组件中，在子组件中就可以调用了。</p><p>组件之间传递数据方法：</p><ol><li>一层一层的传，父-》子-》孙-》重孙-》。。。。 （优点：简单 缺点：层级多时很复杂）</li><li>使用 redux（优点：组件间共享数据 缺点：需要安装并且代码稍微有些难度）</li><li>Context：React 中有一个 Context 技术，可以用来父向子孙组件共享数据。</li></ol><p>综合来看使用 Context 来共享数据比较方便。</p><p>实际操作：</p><ol><li>在父组件中封装一个函数，用这个函数来执行动画<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w3e7udwj30vs0i4gvq.jpg" alt="image.png"></li><li>通过 Context 组件把这个函数共享给所有子组件<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w36nspzj318g0ge4en.jpg" alt="image.png"></li><li>在子组件中就可以使用 Context 来得到这个函数并调用</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w2p3xlbj31ce0f8ne5.jpg" alt="image.png">)<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w2wt7s9j30ki0pkqcu.jpg" alt="image.png"></p><h3 id="扩展问题：函数写在组件中和写在组件外区别？"><a href="#扩展问题：函数写在组件中和写在组件外区别？" class="headerlink" title="扩展问题：函数写在组件中和写在组件外区别？"></a>扩展问题：函数写在组件中和写在组件外区别？</h3><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w2gto6yj31200rynfv.jpg" alt="image.png"></p><p>所以一般需要操作数据，函数都写在组件中。</p><p>有什么办法能避免在组件中定义的函数在组件更新时重复定义吗？<br>答：使用 <code>useCallback</code> 来定义函数。</p><h3 id="知识点总结：使用-Context-为子组件共享数据"><a href="#知识点总结：使用-Context-为子组件共享数据" class="headerlink" title="知识点总结：使用 Context 为子组件共享数据"></a>知识点总结：使用 Context 为子组件共享数据</h3><ol><li>创建一个 Context<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w259fb3j31160esgw8.jpg" alt="image.png"></li><li>在父组件中引入并使用</li></ol><p>引入</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w1x0u5pj30y20l8nd1.jpg" alt="image.png"></p><p>把子组件套起来</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w1pxponj313m0g2ncp.jpg" alt="image.png"></p><ol start="3"><li>在子组件中引入使用</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w1ipnhaj314i0mwavy.jpg" alt="image.png"></p><h3 id="制作我的抽屉导航"><a href="#制作我的抽屉导航" class="headerlink" title="制作我的抽屉导航"></a>制作我的抽屉导航</h3><h4 id="问题一、无法写在子页面中"><a href="#问题一、无法写在子页面中" class="headerlink" title="问题一、无法写在子页面中"></a>问题一、无法写在子页面中</h4><p>通过测试，发现如果把抽屉按钮写在子页面中无法定位到 整个 APP的右面</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w138kbcj31a613y4qp.jpg" alt="image.png"></p><p>所以这个抽屉的按钮虽然是显示在我的这个子页面中的，但代码还是要写在最外层的组件中，否则无法定位到整个 APP 的最右边：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w0dqsofj31eo1224qp.jpg" alt="image.png"></p><h4 id="调整抽屉导航的位置"><a href="#调整抽屉导航的位置" class="headerlink" title="调整抽屉导航的位置"></a>调整抽屉导航的位置</h4><p>因为整个 APP 向左滑动了 75% ，所以抽屉的宽度和位置也是 75%：</p><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2w05fjd0j31eu13stzu.jpg" alt="image.png"></p><h4 id="把原-Drawer-组件中的按钮拿过来"><a href="#把原-Drawer-组件中的按钮拿过来" class="headerlink" title="把原 Drawer 组件中的按钮拿过来"></a>把原 Drawer 组件中的按钮拿过来</h4><p>我们之前已经写了一个 Menu 组件，现在只要复制到这个框里即可：</p><ol><li>引入 Menu 组件<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vzuypdyj30us0fsqd1.jpg" alt="image.png"></li><li>放到框中</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vznm9evj30ow0cq0yj.jpg" alt="image.png"></p><p>现在存在一个问题，导航上的按钮不能点击。<br>原因：在屏幕之外的内容不能点击。</p><h4 id="解决不能点击的问题：将导航按钮也放到屏幕中"><a href="#解决不能点击的问题：将导航按钮也放到屏幕中" class="headerlink" title="解决不能点击的问题：将导航按钮也放到屏幕中"></a>解决不能点击的问题：将导航按钮也放到屏幕中</h4><ol><li>先把导航从主 APP 中拿出来<br>（目的：让主 APP 向左滑动时，导航不要随着滑动）<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vzfqbccj31fs0ww7o6.jpg" alt="image.png"></li><li>把导航先放到外边去<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vz8ol4zj31780t44qp.jpg" alt="image.png"></li><li>给抽屉导航也添加一个动画，让它滚动回屏幕中<br>这样就在屏幕中了，就可以点击了</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vyyj2m1j31aa15c1kx.jpg" alt="image.png"></p><h3 id="通过滑动关闭抽屉导航"><a href="#通过滑动关闭抽屉导航" class="headerlink" title="通过滑动关闭抽屉导航"></a>通过滑动关闭抽屉导航</h3><p>现在我们只能通过点击按钮来打开和关闭，但实际应该可以通过手势左右滑动就可以打开关闭抽屉 。<br>好了，接下来我们实现通过向右滑动来关闭抽屉。</p><p>在 RN 中提供了一个 <code>PanResponder</code> 组件可以实现左右滑动。<br>实际流程：</p><ol><li>创建一个监听左右滑动的组件<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vybvzbfj30ts09wafx.jpg" alt="image.png">)<img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vyjoxq8j314m0o8kdq.jpg" alt="image.png"></li><li>把监听滑动的组件绑定到一个元素上</li></ol><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vy2nizvj30rs0kadp5.jpg" alt="image.png"></p><h3 id="知识点：PanResponder-组件介绍"><a href="#知识点：PanResponder-组件介绍" class="headerlink" title="知识点：PanResponder 组件介绍"></a>知识点：PanResponder 组件介绍</h3><p><img src="http://ww1.sinaimg.cn/large/007WurYGgy1gf2vxvdnasj31i40z0e81.jpg" alt="image.png"></p><br><h1 id="总结"><a href="#总结" class="headerlink" title="总结"></a>总结</h1><ol><li>在使用 React 做开发时有两种写法：</li></ol><ul><li>类组件</li><li>函数组件 + Hook （用的这种）</li></ul><ol start="2"><li>React 组件之间共享数据的方案：</li></ol><ul><li>使用 React 自带的 Context + Reducer 功能 （用的这种）<br>优点：无须引入其他的包<br>缺点：只能向子组件及子孙组件中共享数据</li><li>使用 Redux 实际组件之间的共享<br>优点：数据全都放到 Redux 中管理，无论什么层级都直接使用<br>缺点：需要单独安装，数据状态由它统一管理，很多代码写法不太一样</li></ul><ol start="3"><li>RN 中的布局</li></ol><ul><li>View 组件默认是相对定位的（可以直接使用 left 、top 相对于原来的位置定位）</li><li>View 组件的绝对定位都是相对于父组件定位的（因为父组件都是相对定位，所以默认都是子绝父相）</li><li>没有浮动，只能 flex</li><li>父组件一定要设置高度或者 flex:1 ，否则高度为0页面空白</li></ul><br></div><footer class="post-footer"><div class="post-tags"><a href="/tags/ReactNative/" rel="tag"><i class="fa fa-tag"></i> ReactNative</a></div><div class="post-nav"><div class="post-nav-next post-nav-item"><a href="/article/2a16eda9.html" rel="next" title="数据结构与算法 (js版)  -- 数据结构"><i class="fa fa-chevron-left"></i> 数据结构与算法 (js版) -- 数据结构</a></div><span class="post-nav-divider"></span><div class="post-nav-prev post-nav-item"> <a href="/article/af58ca43.html" rel="prev" title="Vue -- 入门">Vue -- 入门<i class="fa fa-chevron-right"></i></a></div></div></footer></div></article><div class="post-spread"></div></div></div><div class="comments" id="comments"></div></div><div class="sidebar-toggle"><div class="sidebar-toggle-line-wrap"><span class="sidebar-toggle-line sidebar-toggle-line-first"></span><span class="sidebar-toggle-line sidebar-toggle-line-middle"></span><span class="sidebar-toggle-line sidebar-toggle-line-last"></span></div></div><aside id="sidebar" class="sidebar"><div class="sidebar-inner"><ul class="sidebar-nav motion-element"><li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap"> 文章目录</li><li class="sidebar-nav-overview" data-target="site-overview-wrap"> 站点概览</li></ul><section class="site-overview-wrap sidebar-panel"><div class="site-overview"><div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person"> <img class="site-author-image" itemprop="image" src="http://ww1.sinaimg.cn/large/007WurYGgy1ge8nxttd9nj302s02s0si.jpg" alt="King-XiYu"><p class="site-author-name" itemprop="name">King-XiYu</p><p class="site-description motion-element" itemprop="description">有志者事竟成</p></div><nav class="site-state motion-element"><div class="site-state-item site-state-posts"> <a href="/archives/"><span class="site-state-item-count">37</span> <span class="site-state-item-name">日志</span></a></div><div class="site-state-item site-state-categories"> <a href="/categories/index.html"><span class="site-state-item-count">11</span> <span class="site-state-item-name">分类</span></a></div><div class="site-state-item site-state-tags"> <a href="/tags/index.html"><span class="site-state-item-count">10</span> <span class="site-state-item-name">标签</span></a></div></nav><div class="feed-link motion-element"><a href="/atom.xml" rel="alternate"><i class="fa fa-rss"></i> RSS</a></div><div class="links-of-author motion-element"><span class="links-of-author-item"><a href="https://gitee.com/King-XiYu" target="_blank" title="Gitee"><i class="fa fa-fw fa-hand-o-right"></i> Gitee</a></span><span class="links-of-author-item"><a href="https://github.com/King-XiYu" target="_blank" title="GitHub"><i class="fa fa-fw fa-github"></i> GitHub</a></span></div><div class="links-of-blogroll motion-element links-of-blogroll-inline"><div class="links-of-blogroll-title"><i class="fa fa-fw fa-link"></i> Links</div><ul class="links-of-blogroll-list"><li class="links-of-blogroll-item"> <a href="https://www.baidu.com/" title="度娘" target="_blank">度娘</a></li><li class="links-of-blogroll-item"> <a href="https://www.google.com/" title="Google" target="_blank">Google</a></li></ul></div></div></section><section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active"><div class="post-toc"><div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#创建项目"><span class="nav-number">1.</span> <span class="nav-text">创建项目</span></a></li><li class="nav-item nav-level-1"><a class="nav-link" href="#安装-React-Navigation"><span class="nav-number">2.</span> <span class="nav-text">安装 React Navigation</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#安装基础包"><span class="nav-number">2.1.</span> <span class="nav-text">安装基础包</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装依赖包"><span class="nav-number">2.2.</span> <span class="nav-text">安装依赖包</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#首页配置"><span class="nav-number">2.3.</span> <span class="nav-text">首页配置</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装导航器"><span class="nav-number">2.4.</span> <span class="nav-text">安装导航器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装图标库"><span class="nav-number">2.5.</span> <span class="nav-text">安装图标库</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装包"><span class="nav-number">2.5.1.</span> <span class="nav-text">安装包</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置"><span class="nav-number">2.5.2.</span> <span class="nav-text">配置</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装-ViewPager"><span class="nav-number">2.6.</span> <span class="nav-text">安装 ViewPager</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装拍照录像包"><span class="nav-number">2.7.</span> <span class="nav-text">安装拍照录像包</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#安装包-1"><span class="nav-number">2.7.1.</span> <span class="nav-text">安装包</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置1"><span class="nav-number">2.7.2.</span> <span class="nav-text">配置1</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置2"><span class="nav-number">2.7.3.</span> <span class="nav-text">配置2</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#配置3、添加权限"><span class="nav-number">2.7.4.</span> <span class="nav-text">配置3、添加权限</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装视频播放器"><span class="nav-number">2.8.</span> <span class="nav-text">安装视频播放器</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#安装tabview"><span class="nav-number">2.9.</span> <span class="nav-text">安装tabview</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#页面结构导航"><span class="nav-number">3.</span> <span class="nav-text">页面结构导航</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#创建页面结构"><span class="nav-number">3.1.</span> <span class="nav-text">创建页面结构</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#创建导航器"><span class="nav-number">3.2.</span> <span class="nav-text">创建导航器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#引入导航容器"><span class="nav-number">3.2.1.</span> <span class="nav-text">引入导航容器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#创建底部导航器把主页面中四大块页面管理起来"><span class="nav-number">3.2.2.</span> <span class="nav-text">创建底部导航器把主页面中四大块页面管理起来</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在首页中再使用-Stack-导航器管理子页面"><span class="nav-number">3.2.3.</span> <span class="nav-text">在首页中再使用 Stack 导航器管理子页面</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#封面页"><span class="nav-number">4.</span> <span class="nav-text">封面页</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#下载图片"><span class="nav-number">4.1.</span> <span class="nav-text">下载图片</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#编写-Splash-页"><span class="nav-number">4.2.</span> <span class="nav-text">编写 Splash 页</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#首页"><span class="nav-number">5.</span> <span class="nav-text">首页</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#视频播放页"><span class="nav-number">5.1.</span> <span class="nav-text">视频播放页</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#制作图标按钮组件"><span class="nav-number">5.1.1.</span> <span class="nav-text">制作图标按钮组件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#图标按钮"><span class="nav-number">5.1.1.1.</span> <span class="nav-text">图标按钮</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#头像组件"><span class="nav-number">5.1.2.</span> <span class="nav-text">头像组件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#静态头像组件"><span class="nav-number">5.1.2.1.</span> <span class="nav-text">静态头像组件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#旋转的头像组件"><span class="nav-number">5.1.2.2.</span> <span class="nav-text">旋转的头像组件</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#红心点赞组件"><span class="nav-number">5.1.3.</span> <span class="nav-text">红心点赞组件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#先下载两张图片"><span class="nav-number">5.1.3.1.</span> <span class="nav-text">先下载两张图片</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#编写红心点赞组件"><span class="nav-number">5.1.4.</span> <span class="nav-text">编写红心点赞组件</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#带文本的图标按钮组件"><span class="nav-number">5.2.</span> <span class="nav-text">带文本的图标按钮组件</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#全屏的视频播放组件"><span class="nav-number">5.2.1.</span> <span class="nav-text">全屏的视频播放组件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#全屏视频播放组件01-全屏播放"><span class="nav-number">5.2.1.1.</span> <span class="nav-text">全屏视频播放组件01-全屏播放</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#全屏视频播放组件02-右侧的图标按钮"><span class="nav-number">5.2.1.2.</span> <span class="nav-text">全屏视频播放组件02-右侧的图标按钮</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#全屏视频播放组件03-评论框"><span class="nav-number">5.2.1.3.</span> <span class="nav-text">全屏视频播放组件03-评论框</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#抖音底部导航栏"><span class="nav-number">5.3.</span> <span class="nav-text">抖音底部导航栏</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#抖音样式的底部导航栏"><span class="nav-number">5.3.1.</span> <span class="nav-text">抖音样式的底部导航栏</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实现基本样式"><span class="nav-number">5.3.2.</span> <span class="nav-text">实现基本样式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实现中间的按钮"><span class="nav-number">5.3.3.</span> <span class="nav-text">实现中间的按钮</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#按钮平均分布"><span class="nav-number">5.3.4.</span> <span class="nav-text">按钮平均分布</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#实现录像功能"><span class="nav-number">5.3.5.</span> <span class="nav-text">实现录像功能</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#视频列表"><span class="nav-number">5.4.</span> <span class="nav-text">视频列表</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#上下滑动"><span class="nav-number">5.4.1.</span> <span class="nav-text">上下滑动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#左右滑动"><span class="nav-number">5.4.2.</span> <span class="nav-text">左右滑动</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#安装"><span class="nav-number">5.4.2.1.</span> <span class="nav-text">安装</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用"><span class="nav-number">5.4.2.2.</span> <span class="nav-text">使用</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#通过点击按钮实现滑动"><span class="nav-number">5.4.2.3.</span> <span class="nav-text">通过点击按钮实现滑动</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#实现首页四个顶部按钮的布局"><span class="nav-number">5.4.2.4.</span> <span class="nav-text">实现首页四个顶部按钮的布局</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#封装文字按钮"><span class="nav-number">5.4.2.5.</span> <span class="nav-text">封装文字按钮</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#按钮下面的白色条"><span class="nav-number">5.4.2.6.</span> <span class="nav-text">按钮下面的白色条</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#先制作白线"><span class="nav-number">5.4.2.6.1.</span> <span class="nav-text">先制作白线</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#制作白线的移动动画"><span class="nav-number">5.4.2.6.2.</span> <span class="nav-text">制作白线的移动动画</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#使用转换实现动画"><span class="nav-number">5.4.2.7.</span> <span class="nav-text">使用转换实现动画</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#在左右滑动时，白线也移动"><span class="nav-number">5.4.2.8.</span> <span class="nav-text">在左右滑动时，白线也移动</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#不同屏幕尺寸适配"><span class="nav-number">5.4.2.9.</span> <span class="nav-text">不同屏幕尺寸适配</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#解决首页评论嵌套-FlatList-组件的问题"><span class="nav-number">5.5.</span> <span class="nav-text">解决首页评论嵌套 FlatList 组件的问题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#先封装评论条目组件"><span class="nav-number">5.5.1.</span> <span class="nav-text">先封装评论条目组件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在首页评论框中使用-FlatList-组件来制作评论条目的列表"><span class="nav-number">5.5.2.</span> <span class="nav-text">在首页评论框中使用 FlatList 组件来制作评论条目的列表</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#把外层这个评论框单独制作成一个组件"><span class="nav-number">5.5.3.</span> <span class="nav-text">把外层这个评论框单独制作成一个组件</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#封装-Panel-组件"><span class="nav-number">5.5.3.1.</span> <span class="nav-text">封装 Panel 组件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#添加动画"><span class="nav-number">5.5.3.2.</span> <span class="nav-text">添加动画</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#控制组件的打开"><span class="nav-number">5.5.4.</span> <span class="nav-text">控制组件的打开</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#添加一个-onClose-事件（双向绑定）"><span class="nav-number">5.5.4.1.</span> <span class="nav-text">添加一个 onClose 事件（双向绑定）</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#跨层级使用这个-Panel-组件"><span class="nav-number">5.5.4.2.</span> <span class="nav-text">跨层级使用这个 Panel 组件</span></a></li></ol></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#同城页面"><span class="nav-number">6.</span> <span class="nav-text">同城页面</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#创建栈导航器管理两个页面"><span class="nav-number">6.1.</span> <span class="nav-text">创建栈导航器管理两个页面</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#制作城市列表页"><span class="nav-number">6.2.</span> <span class="nav-text">制作城市列表页</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#配置标题栏"><span class="nav-number">6.2.1.</span> <span class="nav-text">配置标题栏</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#列表页的状态栏"><span class="nav-number">6.2.2.</span> <span class="nav-text">列表页的状态栏</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#动态设置标题栏"><span class="nav-number">6.2.3.</span> <span class="nav-text">动态设置标题栏</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#视频列表-1"><span class="nav-number">6.2.4.</span> <span class="nav-text">视频列表</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#背景图片"><span class="nav-number">6.2.4.1.</span> <span class="nav-text">背景图片</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#两列数据"><span class="nav-number">6.2.4.2.</span> <span class="nav-text">两列数据</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#下拉刷新"><span class="nav-number">6.2.4.3.</span> <span class="nav-text">下拉刷新</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#显示刷新图标"><span class="nav-number">6.2.4.4.</span> <span class="nav-text">显示刷新图标</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#加载数据并隐藏图标"><span class="nav-number">6.2.4.5.</span> <span class="nav-text">加载数据并隐藏图标</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#触底加载更多"><span class="nav-number">6.2.4.6.</span> <span class="nav-text">触底加载更多</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#控制触底加载的频率"><span class="nav-number">6.2.5.</span> <span class="nav-text">控制触底加载的频率</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#详情页"><span class="nav-number">6.3.</span> <span class="nav-text">详情页</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#列表中点击跳转"><span class="nav-number">6.3.1.</span> <span class="nav-text">列表中点击跳转</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#详情页-1"><span class="nav-number">6.3.2.</span> <span class="nav-text">详情页</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#引入全屏播放的组件"><span class="nav-number">6.3.2.1.</span> <span class="nav-text">引入全屏播放的组件</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#让标题栏和状态栏透明"><span class="nav-number">6.3.2.2.</span> <span class="nav-text">让标题栏和状态栏透明</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#自定义标题栏左右按钮图标"><span class="nav-number">6.4.</span> <span class="nav-text">自定义标题栏左右按钮图标</span></a></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#我的页面"><span class="nav-number">7.</span> <span class="nav-text">我的页面</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#我的子页面导航器"><span class="nav-number">7.1.</span> <span class="nav-text">我的子页面导航器</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建子页面"><span class="nav-number">7.1.1.</span> <span class="nav-text">创建子页面</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#创建导航器-1"><span class="nav-number">7.1.2.</span> <span class="nav-text">创建导航器</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#我的个人中心布局"><span class="nav-number">7.1.3.</span> <span class="nav-text">我的个人中心布局</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#我的页面标题栏配置"><span class="nav-number">7.1.3.1.</span> <span class="nav-text">我的页面标题栏配置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#顶部背景图"><span class="nav-number">7.1.3.2.</span> <span class="nav-text">顶部背景图</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#我的头像部分的布局"><span class="nav-number">7.1.3.3.</span> <span class="nav-text">我的头像部分的布局</span></a></li></ol></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#右侧抽屉导航"><span class="nav-number">7.2.</span> <span class="nav-text">右侧抽屉导航</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建-Drawer-组件并实现动画"><span class="nav-number">7.2.1.</span> <span class="nav-text">创建 Drawer 组件并实现动画</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#导航栏上收缩的二级导航"><span class="nav-number">7.2.2.</span> <span class="nav-text">导航栏上收缩的二级导航</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#静态布局"><span class="nav-number">7.2.2.1.</span> <span class="nav-text">静态布局</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#制作折叠动画"><span class="nav-number">7.2.2.2.</span> <span class="nav-text">制作折叠动画</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#制作三角形"><span class="nav-number">7.2.2.2.1.</span> <span class="nav-text">制作三角形</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#添加旋转动画"><span class="nav-number">7.2.2.2.2.</span> <span class="nav-text">添加旋转动画</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#订单按钮和三角色形按钮定位"><span class="nav-number">7.2.2.2.3.</span> <span class="nav-text">订单按钮和三角色形按钮定位</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#制作二级按钮"><span class="nav-number">7.2.2.2.4.</span> <span class="nav-text">制作二级按钮</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#实现折叠动画"><span class="nav-number">7.2.2.2.5.</span> <span class="nav-text">实现折叠动画</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#扩展：跳转对象"><span class="nav-number">7.2.3.</span> <span class="nav-text">扩展：跳转对象</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#tab-导航-和-三列的列表"><span class="nav-number">7.3.</span> <span class="nav-text">tab 导航 和 三列的列表</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#需要使用到的组件"><span class="nav-number">7.3.1.</span> <span class="nav-text">需要使用到的组件</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#三列左右-滑动"><span class="nav-number">7.3.2.</span> <span class="nav-text">三列左右 滑动</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#基本功能"><span class="nav-number">7.3.2.1.</span> <span class="nav-text">基本功能</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#放三个按钮"><span class="nav-number">7.3.2.2.</span> <span class="nav-text">放三个按钮</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#点击三个按钮时滑动框"><span class="nav-number">7.3.2.3.</span> <span class="nav-text">点击三个按钮时滑动框</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#选中按钮的样式"><span class="nav-number">7.3.2.4.</span> <span class="nav-text">选中按钮的样式</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#滑动框时同步更新按钮状态"><span class="nav-number">7.3.2.5.</span> <span class="nav-text">滑动框时同步更新按钮状态</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#黄线跟着滑动"><span class="nav-number">7.3.2.6.</span> <span class="nav-text">黄线跟着滑动</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#画一个黄线"><span class="nav-number">7.3.2.6.1.</span> <span class="nav-text">画一个黄线</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#制作动画"><span class="nav-number">7.3.2.6.2.</span> <span class="nav-text">制作动画</span></a></li></ol></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用-FlatList-实现三列的列表"><span class="nav-number">7.3.3.</span> <span class="nav-text">使用 FlatList 实现三列的列表</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#抽屉导航问题"><span class="nav-number">7.4.</span> <span class="nav-text">抽屉导航问题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#盖住APP"><span class="nav-number">7.4.1.</span> <span class="nav-text">盖住APP</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#整个-APP-整体向左滑动"><span class="nav-number">7.4.2.</span> <span class="nav-text">整个 APP 整体向左滑动</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#扩展知识点：布局时的层级"><span class="nav-number">7.4.3.</span> <span class="nav-text">扩展知识点：布局时的层级</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#透明层"><span class="nav-number">7.4.4.</span> <span class="nav-text">透明层</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#控制透明层的显示和隐藏"><span class="nav-number">7.4.5.</span> <span class="nav-text">控制透明层的显示和隐藏</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#在子组件中控制这个抽屉动画"><span class="nav-number">7.4.6.</span> <span class="nav-text">在子组件中控制这个抽屉动画</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#扩展问题：函数写在组件中和写在组件外区别？"><span class="nav-number">7.4.7.</span> <span class="nav-text">扩展问题：函数写在组件中和写在组件外区别？</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#知识点总结：使用-Context-为子组件共享数据"><span class="nav-number">7.4.8.</span> <span class="nav-text">知识点总结：使用 Context 为子组件共享数据</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#制作我的抽屉导航"><span class="nav-number">7.4.9.</span> <span class="nav-text">制作我的抽屉导航</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#问题一、无法写在子页面中"><span class="nav-number">7.4.9.1.</span> <span class="nav-text">问题一、无法写在子页面中</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#调整抽屉导航的位置"><span class="nav-number">7.4.9.2.</span> <span class="nav-text">调整抽屉导航的位置</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#把原-Drawer-组件中的按钮拿过来"><span class="nav-number">7.4.9.3.</span> <span class="nav-text">把原 Drawer 组件中的按钮拿过来</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#解决不能点击的问题：将导航按钮也放到屏幕中"><span class="nav-number">7.4.9.4.</span> <span class="nav-text">解决不能点击的问题：将导航按钮也放到屏幕中</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#通过滑动关闭抽屉导航"><span class="nav-number">7.4.10.</span> <span class="nav-text">通过滑动关闭抽屉导航</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#知识点：PanResponder-组件介绍"><span class="nav-number">7.4.11.</span> <span class="nav-text">知识点：PanResponder 组件介绍</span></a></li></ol></li></ol></li><li class="nav-item nav-level-1"><a class="nav-link" href="#总结"><span class="nav-number">8.</span> <span class="nav-text">总结</span></a></li></ol></div></div></section><div class="back-to-top"><i class="fa fa-arrow-up"></i> <span id="scrollpercent"><span>0</span>%</span></div></div></aside></div></main><footer id="footer" class="footer"><div class="footer-inner"><div class="copyright">&copy; <span itemprop="copyrightYear">2020</span><span class="with-love"><i class="fa fa-user"></i></span> <span class="author" itemprop="copyrightHolder">宇宙特别帅</span></div></div></footer></div><script type="text/javascript">"[object Function]"!==Object.prototype.toString.call(window.Promise)&&(window.Promise=null)</script><script type="text/javascript" src="/lib/jquery/index.js?v=2.1.3"></script><script type="text/javascript" src="/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script><script type="text/javascript" src="/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script><script type="text/javascript" src="/lib/velocity/velocity.min.js?v=1.2.1"></script><script type="text/javascript" src="/lib/velocity/velocity.ui.min.js?v=1.2.1"></script><script type="text/javascript" src="/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script><script type="text/javascript" src="/lib/canvas-nest/canvas-nest.min.js"></script><script type="text/javascript" src="/js/src/utils.js?v=5.1.4"></script><script type="text/javascript" src="/js/src/motion.js?v=5.1.4"></script><script type="text/javascript" src="/js/src/affix.js?v=5.1.4"></script><script type="text/javascript" src="/js/src/schemes/pisces.js?v=5.1.4"></script><script type="text/javascript" src="/js/src/scrollspy.js?v=5.1.4"></script><script type="text/javascript" src="/js/src/post-details.js?v=5.1.4"></script><script type="text/javascript" src="/js/src/bootstrap.js?v=5.1.4"></script><script src="//cdn1.lncld.net/static/js/3.0.4/av-min.js"></script><script src="//cdn.jsdelivr.net/npm/valine/dist/Valine.min.js"></script><script type="text/javascript">
    var GUEST = ['nick','mail','link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item=>{
      return GUEST.indexOf(item)>-1;
    });
    new Valine({
        el: '#comments' ,
        verify: false,
        notify: true,
        appId: '9DODHXKj6rr1cK4oO07iVBX3-gzGzoHsz',
        appKey: 'aJaxxns4VN5WV9nMimT9aSb1',
        placeholder: 'ヾﾉ≧∀≦)o 来呀！吐槽一番吧！',
        avatar:'mp',
        guest_info:guest,
        pageSize:'10' || 10,
    });
  </script><script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "./public/search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script><script src="https://cdn1.lncld.net/static/js/av-core-mini-0.6.4.js"></script><script>AV.initialize("9DODHXKj6rr1cK4oO07iVBX3-gzGzoHsz","aJaxxns4VN5WV9nMimT9aSb1")</script><script>function showTime(e){var t=new AV.Query(e),c=[],u=$(".leancloud_visitors");u.each(function(){c.push($(this).attr("id").trim())}),t.containedIn("url",c),t.find().done(function(e){var t=".leancloud-visitors-count";if(0!==e.length){for(var n=0;n<e.length;n++){var o=e[n],i=o.get("url"),s=o.get("time"),r=document.getElementById(i);$(r).find(t).text(s)}for(n=0;n<c.length;n++){i=c[n],r=document.getElementById(i);var l=$(r).find(t);""==l.text()&&l.text(0)}}else u.find(t).text(0)}).fail(function(e,t){console.log("Error: "+t.code+" "+t.message)})}function addCount(i){var e=$(".leancloud_visitors"),s=e.attr("id").trim(),r=e.attr("data-flag-title").trim(),t=new AV.Query(i);t.equalTo("url",s),t.find({success:function(e){if(0<e.length){var t=e[0];t.fetchWhenSave(!0),t.increment("time"),t.save(null,{success:function(e){$(document.getElementById(s)).find(".leancloud-visitors-count").text(e.get("time"))},error:function(e,t){console.log("Failed to save Visitor num, with error message: "+t.message)}})}else{var n=new i,o=new AV.ACL;o.setPublicReadAccess(!0),o.setPublicWriteAccess(!0),n.setACL(o),n.set("title",r),n.set("url",s),n.set("time",1),n.save(null,{success:function(e){$(document.getElementById(s)).find(".leancloud-visitors-count").text(e.get("time"))},error:function(e,t){console.log("Failed to create")}})}},error:function(e){console.log("Error:"+e.code+" "+e.message)}})}$(function(){var e=AV.Object.extend("Counter");1==$(".leancloud_visitors").length?addCount(e):1<$(".post-title-link").length&&showTime(e)})</script><script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js"></script><script type="text/javascript" src="/js/src/clipboard-use.js"></script></body></html>